$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)) {
*
* @param string $username
*
- * @return \Wallabag\UserBundle\Entity\User
+ * @return User
*/
private function getUser($username)
{
*/
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));
}
}