]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Repository/EntryRepository.php
Merge pull request #3959 from wallabag/mig-tag-collation
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Repository / EntryRepository.php
index 299b0b27612a476164452e4d64f1d49a5de7d3d2..16c448851f444e73f3652313e1baffaa09ea9e40 100644 (file)
@@ -345,7 +345,7 @@ class EntryRepository extends EntityRepository
      * @param string $url
      * @param int    $userId
      *
-     * @return Entry|bool
+     * @return Entry|false
      */
     public function findByUrlAndUserId($url, $userId)
     {
@@ -362,13 +362,24 @@ class EntryRepository extends EntityRepository
      * @param string $hashedUrl Url hashed using sha1
      * @param int    $userId
      *
-     * @return Entry|bool
+     * @return Entry|false
      */
     public function findByHashedUrlAndUserId($hashedUrl, $userId)
     {
+        // try first using hashed_url (to use the database index)
         $res = $this->createQueryBuilder('e')
             ->where('e.hashedUrl = :hashed_url')->setParameter('hashed_url', $hashedUrl)
-            // ->orWhere('e.givenUrl = :url')->setParameter('url', $url)
+            ->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
+            ->getQuery()
+            ->getResult();
+
+        if (\count($res)) {
+            return current($res);
+        }
+
+        // then try using hashed_given_url (to use the database index)
+        $res = $this->createQueryBuilder('e')
+            ->where('e.hashedGivenUrl = :hashed_given_url')->setParameter('hashed_given_url', $hashedUrl)
             ->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
             ->getQuery()
             ->getResult();