]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/RemoveContact.php
Improve query speed
[friendica.git] / src / Worker / RemoveContact.php
index b07661b7a9068dc6cc6505887081d04e5db6ba1b..2e3f16db3e99da80512b85d80cf98b163f18b4f4 100644 (file)
@@ -7,20 +7,30 @@ namespace Friendica\Worker;
 
 use Friendica\Database\DBA;
 use Friendica\Core\Protocol;
+use Friendica\Model\Item;
 
 require_once 'include/dba.php';
 
 class RemoveContact {
        public static function execute($id) {
 
-               // Only delete if the contact is archived
-               $condition = ['archive' => true, 'network' => Protocol::PHANTOM, 'id' => $id];
-               $r = DBA::exists('contact', $condition);
-               if (!DBA::isResult($r)) {
+               // Only delete if the contact is to be deleted
+               $condition = ['network' => Protocol::PHANTOM, 'id' => $id];
+               $contact = DBA::selectFirst('contact', ['uid'], $condition);
+               if (!DBA::isResult($contact)) {
                        return;
                }
 
                // Now we delete the contact and all depending tables
+               $condition = ['uid' => $contact['uid'], '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]);
        }
 }