From 9bdf7d806b570d10ecdcfb7086bcab2ecc03fe03 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 5 Sep 2024 06:35:38 +0000 Subject: [PATCH] Issue 14413: Ensure that the expiry is performed --- src/Model/Item.php | 7 ++++--- src/Worker/Cron.php | 4 ++++ src/Worker/Expire.php | 4 ++-- src/Worker/ExpirePosts.php | 16 ++++++++++------ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 72d7c364bc..cb5857388a 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -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) diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index a0dcfc2f71..1c21bf5065 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -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'); diff --git a/src/Worker/Expire.php b/src/Worker/Expire.php index 6f2d0edae1..e7d77fdbd7 100644 --- a/src/Worker/Expire.php +++ b/src/Worker/Expire.php @@ -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)) { diff --git a/src/Worker/ExpirePosts.php b/src/Worker/ExpirePosts.php index 582888a78f..c05a92f80a 100644 --- a/src/Worker/ExpirePosts.php +++ b/src/Worker/ExpirePosts.php @@ -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'); } /**