Post expiry: Limit for deletions

This commit is contained in:
Michael 2020-10-17 08:16:17 +00:00
parent a28930f174
commit 5a685427ac
2 changed files with 37 additions and 23 deletions

View file

@ -39,7 +39,13 @@ class ExpirePosts
$expire_days_unclaimed = $expire_days; $expire_days_unclaimed = $expire_days;
} }
$limit = DI::config()->get('system', 'dbclean-expire-limit');
if (empty($limit)) {
return;
}
if (!empty($expire_days)) { if (!empty($expire_days)) {
do {
Logger::notice('Start deleting expired threads', ['expiry_days' => $expire_days]); Logger::notice('Start deleting expired threads', ['expiry_days' => $expire_days]);
$ret = DBA::e("DELETE FROM `item-uri` WHERE `id` IN $ret = DBA::e("DELETE FROM `item-uri` WHERE `id` IN
(SELECT `uri-id` FROM `thread` (SELECT `uri-id` FROM `thread`
@ -52,22 +58,29 @@ class ExpirePosts
OR `item`.`wall` OR `item`.`origin` OR `item`.`wall` OR `item`.`origin`
OR `uri-id` IN (SELECT `uri-id` FROM `post-category` OR `uri-id` IN (SELECT `uri-id` FROM `post-category`
WHERE `uri-id` = `item`.`uri-id`)) WHERE `uri-id` = `item`.`uri-id`))
AND `item`.`parent` = `thread`.`iid`))", $expire_days); AND `item`.`parent` = `thread`.`iid`))
ORDER BY `id` LIMIT ?", $expire_days, $limit);
Logger::notice('Deleted expired threads', ['result' => $ret, 'rows' => DBA::affectedRows()]); $rows = DBA::affectedRows();
Logger::notice('Deleted expired threads', ['result' => $ret, 'rows' => $rows]);
} while ($rows >= $limit);
} }
if (!empty($expire_days_unclaimed)) { if (!empty($expire_days_unclaimed)) {
$expiry_date = DateTimeFormat::utc('now - ' . $expire_days_unclaimed . ' days', DateTimeFormat::MYSQL); $expiry_date = DateTimeFormat::utc('now - ' . $expire_days_unclaimed . ' days', DateTimeFormat::MYSQL);
do {
Logger::notice('Start deleting unclaimed public items', ['expiry_days' => $expire_days_unclaimed, 'expired' => $expiry_date]); Logger::notice('Start deleting unclaimed public items', ['expiry_days' => $expire_days_unclaimed, 'expired' => $expiry_date]);
$ret = DBA::e("DELETE FROM `item-uri` WHERE `id` IN $ret = DBA::e("DELETE FROM `item-uri` WHERE `id` IN
(SELECT `uri-id` FROM `item` WHERE `gravity` = ? AND `uid` = ? AND `received` < ? (SELECT `uri-id` FROM `item` WHERE `gravity` = ? AND `uid` = ? AND `received` < ?
AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `item` WHERE `uid` != ?) AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `item` WHERE `uid` != ?)
AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `item` WHERE `uid` = ? AND `received` > ?))", AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `item` WHERE `uid` = ? AND `received` > ?))
GRAVITY_PARENT, 0, $expiry_date, 0, 0, $expiry_date); ORDER BY `id` LIMIT ?",
GRAVITY_PARENT, 0, $expiry_date, 0, 0, $expiry_date, $limit);
Logger::notice('Deleted unclaimed public items', ['result' => $ret, 'rows' => DBA::affectedRows()]); $rows = DBA::affectedRows();
Logger::notice('Deleted unclaimed public items', ['result' => $ret, 'rows' => $rows]);
} while ($rows >= $limit);
} }
} }
} }

View file

@ -187,7 +187,8 @@ return [
// dbclean-expire-limit (Integer) // dbclean-expire-limit (Integer)
// This defines the number of items that are to be deleted in a single call. // This defines the number of items that are to be deleted in a single call.
// Reduce this value when you are getting memory issues. // Reduce this value when you are getting lock issues.
// A value of 0 disables the deletion process.
'dbclean-expire-limit' => 1000, 'dbclean-expire-limit' => 1000,
// diaspora_test (Boolean) // diaspora_test (Boolean)