Merge pull request #14418 from annando/issue-14413

Issue 14413: Ensure that the expiry is performed
This commit is contained in:
Tobias Diekershoff 2024-09-06 07:17:39 +02:00 committed by GitHub
commit 300ddc6bf2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 11 deletions

View file

@ -2881,10 +2881,10 @@ class Item
return $recipients;
}
public static function expire(int $uid, int $days, string $network = "", bool $force = false)
public static function expire(int $uid, int $days, string $network = "", bool $force = false): int
{
if (!$uid || ($days < 1)) {
return;
return 0;
}
$condition = [
@ -2913,7 +2913,7 @@ class Item
$items = Post::select(['resource-id', 'starred', 'id', 'post-type', 'uid', 'uri-id'], $condition);
if (!DBA::isResult($items)) {
return;
return 0;
}
$expire_items = (bool)DI::pConfig()->get($uid, 'expire', 'items', true);
@ -2955,6 +2955,7 @@ class Item
}
DBA::close($items);
Logger::notice('Expired', ['user' => $uid, 'days' => $days, 'network' => $network, 'force' => $force, 'expired' => $expired, 'expire items' => $expire_items, 'expire notes' => $expire_notes, 'expire starred' => $expire_starred, 'expire photos' => $expire_photos, 'condition' => $condition]);
return $expired;
}
public static function firstPostDate(int $uid, bool $wall = false)

View file

@ -107,12 +107,16 @@ class Cron
Worker::add(Worker::PRIORITY_LOW, 'ExpireSearchIndex');
Worker::add(Worker::PRIORITY_LOW, 'Expire');
Worker::add(Worker::PRIORITY_LOW, 'RemoveUnusedTags');
Worker::add(Worker::PRIORITY_LOW, 'RemoveUnusedContacts');
Worker::add(Worker::PRIORITY_LOW, 'RemoveUnusedAvatars');
Worker::add(Worker::PRIORITY_LOW, 'NodeInfo');
// check upstream version?
Worker::add(Worker::PRIORITY_LOW, 'CheckVersion');

View file

@ -29,8 +29,8 @@ class Expire
$user = DBA::selectFirst('user', ['uid', 'username', 'expire'], ['uid' => $param]);
if (DBA::isResult($user)) {
Logger::info('Expire items', ['user' => $user['uid'], 'username' => $user['username'], 'interval' => $user['expire']]);
Item::expire($user['uid'], $user['expire']);
Logger::info('Expire items done', ['user' => $user['uid'], 'username' => $user['username'], 'interval' => $user['expire']]);
$expired = Item::expire($user['uid'], $user['expire']);
Logger::info('Expire items done', ['user' => $user['uid'], 'username' => $user['username'], 'interval' => $user['expire'], 'expired' => $expired]);
}
return;
} elseif ($param == 'hook' && !empty($hook_function)) {

View file

@ -27,32 +27,36 @@ class ExpirePosts
*/
public static function execute()
{
Logger::notice('Expire posts - start');
if (!DBA::acquireOptimizeLock()) {
Logger::warning('Lock could not be acquired');
Worker::defer();
return;
}
Logger::notice('Expire posts - Delete expired origin posts');
self::deleteExpiredOriginPosts();
Logger::notice('Expire posts - Delete orphaned entries');
self::deleteOrphanedEntries();
Logger::notice('Expire posts - delete unused item-uri entries');
self::deleteUnusedItemUri();
Logger::notice('Expire posts - delete external posts');
self::deleteExpiredExternalPosts();
if (DI::config()->get('system', 'add_missing_posts')) {
Logger::notice('Expire posts - add missing posts');
self::addMissingEntries();
}
Logger::notice('Expire posts - delete unused attachments');
self::deleteUnusedAttachments();
DBA::releaseOptimizeLock();
// Set the expiry for origin posts
Worker::add(Worker::PRIORITY_LOW, 'Expire');
// update nodeinfo data after everything is cleaned up
Worker::add(Worker::PRIORITY_LOW, 'NodeInfo');
Logger::notice('Expire posts - done');
}
/**