]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Change the way to define algorithm for hashing url
authorJeremy Benoist <jeremy.benoist@gmail.com>
Fri, 24 May 2019 13:15:12 +0000 (15:15 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Fri, 24 May 2019 13:17:46 +0000 (15:17 +0200)
src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php
src/Wallabag/CoreBundle/Helper/UrlHasher.php
src/Wallabag/CoreBundle/Repository/EntryRepository.php

index 775b04138f3028cd3754ee79f6fdede90f5446f6..8f2bff114096d4a6ba24578d96d38636bb1f1fb2 100644 (file)
@@ -66,9 +66,7 @@ class GenerateUrlHashesCommand extends ContainerAwareCommand
 
         $i = 1;
         foreach ($entries as $entry) {
-            $entry->setHashedUrl(
-                UrlHasher::hashUrl($entry->getUrl())
-            );
+            $entry->setHashedUrl(UrlHasher::hashUrl($entry->getUrl()));
             $em->persist($entry);
 
             if (0 === ($i % 20)) {
@@ -87,7 +85,7 @@ class GenerateUrlHashesCommand extends ContainerAwareCommand
      *
      * @param string $username
      *
-     * @return \Wallabag\UserBundle\Entity\User
+     * @return User
      */
     private function getUser($username)
     {
index e44f219a81909d8807911892c248116e459b617d..d123eaba34902099f4f5ca28f129a3cfb2015a85 100644 (file)
@@ -7,16 +7,17 @@ namespace Wallabag\CoreBundle\Helper;
  */
 class UrlHasher
 {
-    /** @var string */
-    const ALGORITHM = 'sha1';
-
     /**
+     * Hash the given url using the given algorithm.
+     * Hashed url are faster to be retrieved in the database than the real url.
+     *
      * @param string $url
+     * @param string $algorithm
      *
-     * @return string hashed $url
+     * @return string
      */
-    public static function hashUrl(string $url)
+    public static function hashUrl(string $url, $algorithm = 'sha1')
     {
-        return hash(static::ALGORITHM, $url);
+        return hash($algorithm, urldecode($url));
     }
 }
index 37fc1000fb78af4caf0901e3c3f87807d0600c1b..7c4a05edeef5fe9c425ecf82ccfee0b3168dc88a 100644 (file)
@@ -351,7 +351,8 @@ class EntryRepository extends EntityRepository
     {
         return $this->findByHashedUrlAndUserId(
             UrlHasher::hashUrl($url),
-            $userId);
+            $userId
+        );
     }
 
     /**