mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-29 04:21:06 +00:00
Merge pull request #5261 from wallabag/fix/performance-exists
Improve performance of REST exists call
This commit is contained in:
commit
d7a3f7eb01
2 changed files with 33 additions and 21 deletions
|
@ -67,11 +67,24 @@ class EntryRestController extends WallabagRestController
|
||||||
throw $this->createAccessDeniedException('URL is empty?, logged user id: ' . $this->getUser()->getId());
|
throw $this->createAccessDeniedException('URL is empty?, logged user id: ' . $this->getUser()->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
$results = [];
|
$results = array_fill_keys($hashedUrls, null);
|
||||||
foreach ($hashedUrls as $hashedUrlToSearch) {
|
$res = $repo->findByUserIdAndBatchHashedUrls($this->getUser()->getId(), $hashedUrls);
|
||||||
$res = $repo->findByHashedUrlAndUserId($hashedUrlToSearch, $this->getUser()->getId());
|
foreach ($res as $e) {
|
||||||
|
$_hashedUrl = array_keys($hashedUrls, 'blah', true);
|
||||||
|
if ([] !== array_keys($hashedUrls, $e['hashedUrl'], true)) {
|
||||||
|
$_hashedUrl = $e['hashedUrl'];
|
||||||
|
} elseif ([] !== array_keys($hashedUrls, $e['hashedGivenUrl'], true)) {
|
||||||
|
$_hashedUrl = $e['hashedGivenUrl'];
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$results[$_hashedUrl] = $e['id'];
|
||||||
|
}
|
||||||
|
|
||||||
$results[$hashedUrlToSearch] = $this->returnExistInformation($res, $returnId);
|
if (false === $returnId) {
|
||||||
|
$results = array_map(function ($v) {
|
||||||
|
return null !== $v;
|
||||||
|
}, $results);
|
||||||
}
|
}
|
||||||
|
|
||||||
$results = $this->replaceUrlHashes($results, $urlHashMap);
|
$results = $this->replaceUrlHashes($results, $urlHashMap);
|
||||||
|
@ -840,21 +853,4 @@ class EntryRestController extends WallabagRestController
|
||||||
'origin_url' => $request->request->get('origin_url', ''),
|
'origin_url' => $request->request->get('origin_url', ''),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return information about the entry if it exist and depending on the id or not.
|
|
||||||
*
|
|
||||||
* @param Entry|bool|null $entry
|
|
||||||
* @param bool $returnId
|
|
||||||
*
|
|
||||||
* @return bool|int
|
|
||||||
*/
|
|
||||||
private function returnExistInformation($entry, $returnId)
|
|
||||||
{
|
|
||||||
if ($returnId) {
|
|
||||||
return $entry instanceof Entry ? $entry->getId() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $entry instanceof Entry;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -421,6 +421,22 @@ class EntryRepository extends EntityRepository
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findByUserIdAndBatchHashedUrls($userId, $hashedUrls)
|
||||||
|
{
|
||||||
|
$qb = $this->createQueryBuilder('e')->select(['e.id', 'e.hashedUrl', 'e.hashedGivenUrl']);
|
||||||
|
$res = $qb->where('e.user = :user_id')->setParameter('user_id', $userId)
|
||||||
|
->andWhere(
|
||||||
|
$qb->expr()->orX(
|
||||||
|
$qb->expr()->in('e.hashedUrl', $hashedUrls),
|
||||||
|
$qb->expr()->in('e.hashedGivenUrl', $hashedUrls)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Count all entries for a user.
|
* Count all entries for a user.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue