refactor: cache some more queries
This commit is contained in:
parent
9a2ca7e184
commit
6621dd4772
|
@ -50,7 +50,9 @@ class UserService
|
|||
|
||||
public function setPassword($data)
|
||||
{
|
||||
$user = User::where(['email' => $data['email']])->first();
|
||||
$user = cache()->remember('userExists'.$data['email'], 5, function () use ($data) {
|
||||
return User::where(['email' => $data['email']])->first();
|
||||
});
|
||||
if ($user === null) {
|
||||
return;
|
||||
}
|
||||
|
@ -76,7 +78,9 @@ class UserService
|
|||
|
||||
public function getOneById(string $id): ?User
|
||||
{
|
||||
return cache()->remember('userId'.$id, 5, function () use ($id) {
|
||||
return User::where(['id' => $id])->first();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,7 +106,9 @@ class UserService
|
|||
|
||||
public function getUnexistingIds(array $ids): ?array
|
||||
{
|
||||
$users = User::whereIn('id', $ids)->get();
|
||||
$users = cache()->remember('userWhereIn'.implode(',', $ids), 5, function () use ($ids) {
|
||||
User::whereIn('id', $ids)->get();
|
||||
});
|
||||
if ($users->count() != count($ids)) {
|
||||
$existingIds = $users->map(
|
||||
function ($model) {
|
||||
|
|
Loading…
Reference in New Issue