Improved performance when expiring posts

This commit is contained in:
Michael 2024-06-07 04:02:13 +00:00
parent bfa7e3f7a7
commit b33d603f96

View file

@ -75,14 +75,14 @@ class ExpirePosts
{ {
Logger::notice('Delete expired posts'); Logger::notice('Delete expired posts');
// physically remove anything that has been deleted for more than two months // physically remove anything that has been deleted for more than two months
$condition = ["`gravity` = ? AND `deleted` AND `changed` < ?", Item::GRAVITY_PARENT, DateTimeFormat::utc('now - 60 days')]; $condition = ["`gravity` = ? AND `deleted` AND `edited` < ?", Item::GRAVITY_PARENT, DateTimeFormat::utc('now - 60 days')];
$pass = 0; $pass = 0;
do { do {
++$pass; ++$pass;
$rows = Post::select(['guid', 'uri-id', 'uid'], $condition, ['limit' => 100]); $rows = DBA::select('post-user', ['uri-id', 'uid'], $condition, ['limit' => 1000]);
$affected_count = 0; $affected_count = 0;
while ($row = Post::fetch($rows)) { while ($row = Post::fetch($rows)) {
Logger::info('Delete expired item', ['pass' => $pass, 'uri-id' => $row['uri-id'], 'guid' => $row['guid']]); Logger::info('Delete expired item', ['pass' => $pass, 'uri-id' => $row['uri-id']]);
Post\User::delete(['parent-uri-id' => $row['uri-id'], 'uid' => $row['uid']]); Post\User::delete(['parent-uri-id' => $row['uri-id'], 'uid' => $row['uid']]);
$affected_count += DBA::affectedRows(); $affected_count += DBA::affectedRows();
Post\Origin::delete(['parent-uri-id' => $row['uri-id'], 'uid' => $row['uid']]); Post\Origin::delete(['parent-uri-id' => $row['uri-id'], 'uid' => $row['uid']]);
@ -273,7 +273,7 @@ class ExpirePosts
$pass = 0; $pass = 0;
do { do {
++$pass; ++$pass;
$uris = DBA::select('item-uri', ['id'], $condition, ['limit' => 100]); $uris = DBA::select('item-uri', ['id'], $condition, ['limit' => 1000]);
Logger::notice('Start deleting expired threads', ['pass' => $pass]); Logger::notice('Start deleting expired threads', ['pass' => $pass]);
$affected_count = 0; $affected_count = 0;
@ -301,7 +301,7 @@ class ExpirePosts
$pass = 0; $pass = 0;
do { do {
++$pass; ++$pass;
$uris = DBA::select('item-uri', ['id'], $condition, ['limit' => 100]); $uris = DBA::select('item-uri', ['id'], $condition, ['limit' => 1000]);
Logger::notice('Start deleting unclaimed public items', ['pass' => $pass]); Logger::notice('Start deleting unclaimed public items', ['pass' => $pass]);
$affected_count = 0; $affected_count = 0;