X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FWorker%2FCleanItemUri.php;h=d7a99153f69efaddc14427490ffb916ec968697d;hb=bf8fb215a9cc554b5ec5b774168a52fb56fa43e6;hp=0f24e549f77c39043248cc3d0e6ceec4d7067890;hpb=2db7a4971c4af77de8ae6634455909a515dd60f8;p=friendica.git diff --git a/src/Worker/CleanItemUri.php b/src/Worker/CleanItemUri.php index 0f24e549f7..d7a99153f6 100644 --- a/src/Worker/CleanItemUri.php +++ b/src/Worker/CleanItemUri.php @@ -31,9 +31,19 @@ class CleanItemUri */ public static function execute() { - $ret = DBA::e("DELETE FROM `item-uri` WHERE NOT `id` IN (SELECT `uri-id` FROM `item`) + // We have to avoid deleting newly created "item-uri" entries. + // So we fetch a post that had been stored yesterday and only delete older ones. + $item = DBA::selectFirst('item', ['uri-id'], ["`uid` = ? AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY", 0, 1], + ['order' => ['received' => true]]); + if (empty($item['uri-id'])) { + Logger::warning('No item with uri-id found - we better quit here'); + return; + } + Logger::notice('Start deleting orphaned URI-ID', ['last-id' => $item['uri-id']]); + $ret = DBA::e("DELETE FROM `item-uri` WHERE `id` < ? + AND NOT `id` IN (SELECT `uri-id` FROM `item`) AND NOT `id` IN (SELECT `parent-uri-id` FROM `item`) - AND NOT `id` IN (SELECT `thr-parent-id` FROM `item`)"); + AND NOT `id` IN (SELECT `thr-parent-id` FROM `item`)", $item['uri-id']); Logger::notice('Orphaned URI-ID entries removed', ['result' => $ret, 'rows' => DBA::affectedRows()]); } }