@@ -153,17 +153,31 @@ public static function cleanUpSnapshots(): void
153153
154154 $ cleanup_interval = (int ) $ cleanup_interval ;
155155
156- $ sql = rex_sql::factory ();
157- $ sql ->setTable (rex::getTable ('diff_detect_index ' ));
158- $ sql ->setWhere ('createdate < DATE_SUB(:datetime, INTERVAL :interval SECOND) ' , [
159- 'datetime ' => date (rex_sql::FORMAT_DATETIME ),
160- 'interval ' => $ cleanup_interval ,
161- ]);
162- $ sql ->delete ();
163- if (null !== $ sql ->getError ()) {
164- throw new rex_exception ($ sql ->getError ());
156+ foreach (Url::getAll () as $ URL ) {
157+ $ indeces = rex_sql::factory ()->getArray ('
158+ SELECT *
159+ FROM ' . rex::getTable ('diff_detect_index ' ) . ' as t1
160+ JOIN (
161+ SELECT id
162+ FROM ' . rex::getTable ('diff_detect_index ' ) . '
163+ WHERE url_id = :url_id
164+ ORDER BY createdate DESC
165+ LIMIT 2,100000
166+ ) as t2 ON t1.id = t2.id
167+ WHERE
168+ url_id = :url_id
169+ AND createdate < DATE_SUB(:datetime, INTERVAL :interval SECOND)
170+ ' , [
171+ 'url_id ' => $ URL ->getId (),
172+ 'datetime ' => date (rex_sql::FORMAT_DATETIME ),
173+ 'interval ' => $ cleanup_interval ,
174+ ]);
175+
176+ foreach ($ indeces as $ Index ) {
177+ $ Index = self ::fromSqlData ($ Index );
178+ $ Index ->delete ();
179+ }
165180 }
166-
167181 }
168182
169183 public function setUrl (Url $ url ): self
@@ -189,4 +203,21 @@ public function getContent(): string
189203 $ content = (new Html2Text ($ content ))->getText ();
190204 return $ content ;
191205 }
206+
207+ public function delete (): void
208+ {
209+ $ sql = rex_sql::factory ()->setQuery (
210+ '
211+ DELETE from ' . rex::getTable ('diff_detect_index ' ) . '
212+ WHERE id = :id
213+ ' ,
214+ [
215+ 'id ' => $ this ->getId (),
216+ ],
217+ );
218+
219+ if (null !== $ sql ->getError ()) {
220+ throw new rex_exception ($ sql ->getError ());
221+ }
222+ }
192223}
0 commit comments