From c0a24d80dda2dccf44579b1ae0ddba87abead658 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 24 Oct 2018 04:46:45 +0000 Subject: [PATCH] Remove items more memory friendly --- src/Worker/RemoveContact.php | 10 ++++++++++ src/Worker/RemoveUser.php | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Worker/RemoveContact.php b/src/Worker/RemoveContact.php index 8f986eab11..8485adda6b 100644 --- a/src/Worker/RemoveContact.php +++ b/src/Worker/RemoveContact.php @@ -7,6 +7,7 @@ namespace Friendica\Worker; use Friendica\Database\DBA; use Friendica\Core\Protocol; +use Friendica\Model\Item; require_once 'include/dba.php'; @@ -21,6 +22,15 @@ class RemoveContact { } // Now we delete the contact and all depending tables + $condition = ['contact-id' => $id]; + do { + $items = Item::select(['id'], $condition, ['limit' => 100]); + while ($item = Item::fetch($items)) { + DBA::delete('item', ['id' => $item['id']]); + } + DBA::close($items); + } while (Item::exists($condition)); + DBA::delete('contact', ['id' => $id]); } } diff --git a/src/Worker/RemoveUser.php b/src/Worker/RemoveUser.php index dfa5ccc097..d8966e5a49 100644 --- a/src/Worker/RemoveUser.php +++ b/src/Worker/RemoveUser.php @@ -20,6 +20,13 @@ class RemoveUser { } // Now we delete all user items - Item::delete(['uid' => $uid], PRIORITY_LOW); + $condition = ['uid' => $uid, 'deleted' => false]; + do { + $items = Item::select(['id'], $condition, ['limit' => 100]); + while ($item = Item::fetch($items)) { + Item::deleteById($item['id'], PRIORITY_LOW); + } + DBA::close($items); + } while (Item::exists($condition)); } } -- 2.39.5