- Logger::notice('Start deleting expired threads', ['expiry_days' => $expire_days]);
- $ret = DBA::e("DELETE FROM `item-uri` WHERE `id` IN
- (SELECT `uri-id` FROM `thread`
- INNER JOIN `contact` ON `id` = `contact-id` AND NOT `notify_new_posts`
- WHERE `received` < UTC_TIMESTAMP() - INTERVAL ? DAY
- AND NOT `mention` AND NOT `starred` AND NOT `wall` AND NOT `origin`
- AND `thread`.`uid` != 0 AND NOT `iid` IN (SELECT `parent` FROM `item`
- WHERE (`item`.`starred` OR (`item`.`resource-id` != '')
- OR (`item`.`event-id` != '') OR (`item`.`attach` != '')
- OR `item`.`wall` OR `item`.`origin`
- OR `uri-id` IN (SELECT `uri-id` FROM `post-category`
- WHERE `uri-id` = `item`.`uri-id`))
- AND `item`.`parent` = `thread`.`iid`))", $expire_days);
+ do {
+ Logger::notice('Start deleting expired threads', ['expiry_days' => $expire_days]);
+ $ret = DBA::e("DELETE FROM `item-uri` WHERE `id` IN
+ (SELECT `uri-id` FROM `thread`
+ INNER JOIN `contact` ON `id` = `contact-id` AND NOT `notify_new_posts`
+ WHERE `received` < UTC_TIMESTAMP() - INTERVAL ? DAY
+ AND NOT `mention` AND NOT `starred` AND NOT `wall` AND NOT `origin`
+ AND `thread`.`uid` != 0 AND NOT `iid` IN (SELECT `parent` FROM `item`
+ WHERE (`item`.`starred` OR (`item`.`resource-id` != '')
+ OR (`item`.`event-id` != '') OR (`item`.`attach` != '')
+ OR `item`.`wall` OR `item`.`origin`
+ OR `uri-id` IN (SELECT `uri-id` FROM `post-category`
+ WHERE `uri-id` = `item`.`uri-id`))
+ AND `item`.`parent` = `thread`.`iid`))
+ ORDER BY `id` LIMIT ?", $expire_days, $limit);