mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2026-06-08 21:08:09 +08:00
fix: 优化 SystemService::update ,减少检测时的查询次数
This commit is contained in:
parent
5153a3448b
commit
6fc2d30872
@ -189,10 +189,11 @@ class SystemService extends Service
|
|||||||
public static function update($query, array $data, string $key = 'id', $map = [])
|
public static function update($query, array $data, string $key = 'id', $map = [])
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$query = Helper::buildQuery($query)->master()->strict(false)->where($map);
|
$query = Helper::buildQuery($query)->master()->where($map);
|
||||||
if (empty($map[$key])) $query->where([$key => $data[$key] ?? null]);
|
if (empty($map[$key])) $query->where([$key => $data[$key] ?? null]);
|
||||||
return (clone $query)->count() > 0 ? (clone $query)->update($data) : (clone $query)->findOrEmpty()->save($data);
|
$model = (clone $query)->findOrEmpty();
|
||||||
} catch (\Exception $exception) {
|
return $model->isExists() ? (clone $query)->strict(false)->update($data) : $model->save($data);
|
||||||
|
} catch (\Exception|\Throwable $exception) {
|
||||||
throw new Exception($exception->getMessage(), $exception->getCode());
|
throw new Exception($exception->getMessage(), $exception->getCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user