diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2019-06-05 11:38:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-05 11:38:00 +0200 |
commit | 16e1c07553d276f6a4df8fb0f2d1aa25026d73be (patch) | |
tree | 30771618e781968dbbc79fa7113db266017a35ae /src | |
parent | 8671da5eadc93204f2742bb6b2b5b8fc1eddf131 (diff) | |
parent | d8809f70ea3a2f88635827b37af23b2fc2a93db6 (diff) | |
download | wallabag-16e1c07553d276f6a4df8fb0f2d1aa25026d73be.tar.gz wallabag-16e1c07553d276f6a4df8fb0f2d1aa25026d73be.tar.zst wallabag-16e1c07553d276f6a4df8fb0f2d1aa25026d73be.zip |
Merge pull request #3271 from wallabag/store-resolved-url
Add `given_url` in Entry table to check if a redirected url has already added
Diffstat (limited to 'src')
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/Entry.php | 68 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/ContentProxy.php | 2 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/EntryRepository.php | 12 |
3 files changed, 72 insertions, 10 deletions
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 8637c62f..4d5e6fc9 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php | |||
@@ -27,7 +27,8 @@ use Wallabag\UserBundle\Entity\User; | |||
27 | * indexes={ | 27 | * indexes={ |
28 | * @ORM\Index(name="created_at", columns={"created_at"}), | 28 | * @ORM\Index(name="created_at", columns={"created_at"}), |
29 | * @ORM\Index(name="uid", columns={"uid"}), | 29 | * @ORM\Index(name="uid", columns={"uid"}), |
30 | * @ORM\Index(name="hashed_url_user_id", columns={"user_id", "hashed_url"}, options={"lengths"={null, 40}}) | 30 | * @ORM\Index(name="hashed_url_user_id", columns={"user_id", "hashed_url"}, options={"lengths"={null, 40}}), |
31 | * @ORM\Index(name="hashed_given_url_user_id", columns={"user_id", "hashed_given_url"}, options={"lengths"={null, 40}}) | ||
31 | * } | 32 | * } |
32 | * ) | 33 | * ) |
33 | * @ORM\HasLifecycleCallbacks() | 34 | * @ORM\HasLifecycleCallbacks() |
@@ -68,6 +69,8 @@ class Entry | |||
68 | private $title; | 69 | private $title; |
69 | 70 | ||
70 | /** | 71 | /** |
72 | * Define the url fetched by wallabag (the final url after potential redirections). | ||
73 | * | ||
71 | * @var string | 74 | * @var string |
72 | * | 75 | * |
73 | * @Assert\NotBlank() | 76 | * @Assert\NotBlank() |
@@ -85,6 +88,35 @@ class Entry | |||
85 | private $hashedUrl; | 88 | private $hashedUrl; |
86 | 89 | ||
87 | /** | 90 | /** |
91 | * From where user retrieved/found the url (an other article, a twitter, or the given_url if non are provided). | ||
92 | * | ||
93 | * @var string | ||
94 | * | ||
95 | * @ORM\Column(name="origin_url", type="text", nullable=true) | ||
96 | * | ||
97 | * @Groups({"entries_for_user", "export_all"}) | ||
98 | */ | ||
99 | private $originUrl; | ||
100 | |||
101 | /** | ||
102 | * Define the url entered by the user (without redirections). | ||
103 | * | ||
104 | * @var string | ||
105 | * | ||
106 | * @ORM\Column(name="given_url", type="text", nullable=true) | ||
107 | * | ||
108 | * @Groups({"entries_for_user", "export_all"}) | ||
109 | */ | ||
110 | private $givenUrl; | ||
111 | |||
112 | /** | ||
113 | * @var string | ||
114 | * | ||
115 | * @ORM\Column(name="hashed_given_url", type="string", length=40, nullable=true) | ||
116 | */ | ||
117 | private $hashedGivenUrl; | ||
118 | |||
119 | /** | ||
88 | * @var bool | 120 | * @var bool |
89 | * | 121 | * |
90 | * @Exclude | 122 | * @Exclude |
@@ -263,15 +295,6 @@ class Entry | |||
263 | */ | 295 | */ |
264 | private $tags; | 296 | private $tags; |
265 | 297 | ||
266 | /** | ||
267 | * @var string | ||
268 | * | ||
269 | * @ORM\Column(name="origin_url", type="text", nullable=true) | ||
270 | * | ||
271 | * @Groups({"entries_for_user", "export_all"}) | ||
272 | */ | ||
273 | private $originUrl; | ||
274 | |||
275 | /* | 298 | /* |
276 | * @param User $user | 299 | * @param User $user |
277 | */ | 300 | */ |
@@ -923,6 +946,31 @@ class Entry | |||
923 | } | 946 | } |
924 | 947 | ||
925 | /** | 948 | /** |
949 | * Set given url. | ||
950 | * | ||
951 | * @param string $givenUrl | ||
952 | * | ||
953 | * @return Entry | ||
954 | */ | ||
955 | public function setGivenUrl($givenUrl) | ||
956 | { | ||
957 | $this->givenUrl = $givenUrl; | ||
958 | $this->hashedGivenUrl = UrlHasher::hashUrl($givenUrl); | ||
959 | |||
960 | return $this; | ||
961 | } | ||
962 | |||
963 | /** | ||
964 | * Get given url. | ||
965 | * | ||
966 | * @return string | ||
967 | */ | ||
968 | public function getGivenUrl() | ||
969 | { | ||
970 | return $this->givenUrl; | ||
971 | } | ||
972 | |||
973 | /** | ||
926 | * @return string | 974 | * @return string |
927 | */ | 975 | */ |
928 | public function getHashedUrl() | 976 | public function getHashedUrl() |
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index c6fa0d98..5901df8b 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php | |||
@@ -78,6 +78,8 @@ class ContentProxy | |||
78 | $entry->setUrl($url); | 78 | $entry->setUrl($url); |
79 | } | 79 | } |
80 | 80 | ||
81 | $entry->setGivenUrl($url); | ||
82 | |||
81 | $this->stockEntry($entry, $content); | 83 | $this->stockEntry($entry, $content); |
82 | } | 84 | } |
83 | 85 | ||
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index f9cf5233..16c44885 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php | |||
@@ -366,6 +366,7 @@ class EntryRepository extends EntityRepository | |||
366 | */ | 366 | */ |
367 | public function findByHashedUrlAndUserId($hashedUrl, $userId) | 367 | public function findByHashedUrlAndUserId($hashedUrl, $userId) |
368 | { | 368 | { |
369 | // try first using hashed_url (to use the database index) | ||
369 | $res = $this->createQueryBuilder('e') | 370 | $res = $this->createQueryBuilder('e') |
370 | ->where('e.hashedUrl = :hashed_url')->setParameter('hashed_url', $hashedUrl) | 371 | ->where('e.hashedUrl = :hashed_url')->setParameter('hashed_url', $hashedUrl) |
371 | ->andWhere('e.user = :user_id')->setParameter('user_id', $userId) | 372 | ->andWhere('e.user = :user_id')->setParameter('user_id', $userId) |
@@ -376,6 +377,17 @@ class EntryRepository extends EntityRepository | |||
376 | return current($res); | 377 | return current($res); |
377 | } | 378 | } |
378 | 379 | ||
380 | // then try using hashed_given_url (to use the database index) | ||
381 | $res = $this->createQueryBuilder('e') | ||
382 | ->where('e.hashedGivenUrl = :hashed_given_url')->setParameter('hashed_given_url', $hashedUrl) | ||
383 | ->andWhere('e.user = :user_id')->setParameter('user_id', $userId) | ||
384 | ->getQuery() | ||
385 | ->getResult(); | ||
386 | |||
387 | if (\count($res)) { | ||
388 | return current($res); | ||
389 | } | ||
390 | |||
379 | return false; | 391 | return false; |
380 | } | 392 | } |
381 | 393 | ||