The item table is now completely removed

This commit is contained in:
Michael 2021-02-19 06:30:38 +00:00
commit c247d5fbeb
12 changed files with 121 additions and 348 deletions

View file

@ -54,19 +54,6 @@ class APDelivery
return;
}
if (empty($uri_id) && !empty($item_id)) {
$item = Post::selectFirst(['uri-id', 'id'], ['item-id' => $item_id]);
if (!empty($item['uri-id'])) {
$uri_id = $item['uri-id'];
$item_id = $item['id'];
}
} elseif (!empty($uri_id) && !empty($item_id)) {
$item = Post::selectFirst(['id'], ['uri-id' => $uri_id, 'uid' => $uid]);
if (!empty($item['uri-id'])) {
$item_id = $item['id'];
}
}
Logger::info('Invoked', ['cmd' => $cmd, 'inbox' => $inbox, 'id' => $item_id, 'uri-id' => $uri_id, 'uid' => $uid]);
$success = true;
@ -93,7 +80,6 @@ class APDelivery
}
}
// This should never fail and is temporariy (until the move to the "post" structure)
$gsid = null;
foreach ($receivers as $receiver) {

View file

@ -55,49 +55,33 @@ class Delivery
{
Logger::info('Invoked', ['cmd' => $cmd, 'target' => $post_uriid, 'sender_uid' => $sender_uid, 'contact' => $contact_id]);
$target_id = $post_uriid;
if (!empty($sender_uid)) {
$post = Post::selectFirst(['id'], ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
if (!DBA::isResult($post)) {
Logger::warning('Post not found', ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
return;
}
$target_id = $post['id'];
} elseif (!in_array($cmd, [Delivery::MAIL, Delivery::SUGGESTION, Delivery::REMOVAL, Delivery::RELOCATION])) {
$post = Post::selectFirst(['id', 'uid', 'uri-id'], ['item-id' => $post_uriid]);
if (DBA::isResult($post)) {
$target_id = $post['id'];
$sender_uid = $post['uid'];
$post_uriid = $post['uri-id'];
}
}
$top_level = false;
$followup = false;
$public_message = false;
$items = [];
if ($cmd == self::MAIL) {
$target_item = DBA::selectFirst('mail', [], ['id' => $target_id]);
$target_item = DBA::selectFirst('mail', [], ['id' => $post_uriid]);
if (!DBA::isResult($target_item)) {
return;
}
$uid = $target_item['uid'];
} elseif ($cmd == self::SUGGESTION) {
$target_item = DBA::selectFirst('fsuggest', [], ['id' => $target_id]);
$target_item = DBA::selectFirst('fsuggest', [], ['id' => $post_uriid]);
if (!DBA::isResult($target_item)) {
return;
}
$uid = $target_item['uid'];
} elseif ($cmd == self::RELOCATION) {
$uid = $target_id;
$uid = $post_uriid;
$target_item = [];
} else {
$item = Model\Post::selectFirst(['parent'], ['id' => $target_id]);
$item = Model\Post::selectFirst(['id', 'parent'], ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
if (!DBA::isResult($item) || empty($item['parent'])) {
Logger::warning('Post not found', ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
return;
}
$target_id = intval($item['id']);
$parent_id = intval($item['parent']);
$condition = ['id' => [$target_id, $parent_id], 'visible' => true];

View file

@ -45,11 +45,11 @@ class Expire
Logger::log('Delete expired items', Logger::DEBUG);
// physically remove anything that has been deleted for more than two months
$condition = ["`deleted` AND `changed` < UTC_TIMESTAMP() - INTERVAL 60 DAY"];
$rows = Post::select(['item-id', 'guid', 'uri-id', 'uid'], $condition);
$rows = Post::select(['guid', 'uri-id', 'uid'], $condition);
while ($row = Post::fetch($rows)) {
Logger::info('Delete expired item', ['id' => $row['item-id'], 'guid' => $row['guid']]);
Logger::info('Delete expired item', ['uri-id' => $row['uri-id'], 'guid' => $row['guid']]);
if (DBStructure::existsTable('item')) {
DBA::delete('item', ['id' => $row['item-id']]);
DBA::delete('item', ['uri-id' => $row['uri-id'], 'uid' => $row['uid']]);
}
Post\User::delete(['uri-id' => $row['uri-id'], 'uid' => $row['uid']]);
Post\ThreadUser::delete(['uri-id' => $row['uri-id'], 'uid' => $row['uid']]);

View file

@ -60,23 +60,6 @@ class Notifier
Logger::info('Invoked', ['cmd' => $cmd, 'target' => $post_uriid, 'sender_uid' => $sender_uid]);
$target_id = $post_uriid;
if (!empty($sender_uid)) {
$post = Post::selectFirst(['id'], ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
if (!DBA::isResult($post)) {
Logger::warning('Post not found', ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
return;
}
$target_id = $post['id'];
} elseif (!in_array($cmd, [Delivery::MAIL, Delivery::SUGGESTION, Delivery::REMOVAL, Delivery::RELOCATION])) {
$post = Post::selectFirst(['id', 'uid', 'uri-id'], ['item-id' => $post_uriid]);
if (DBA::isResult($post)) {
$target_id = $post['id'];
$sender_uid = $post['uid'];
$post_uriid = $post['uri-id'];
}
}
$top_level = false;
$recipients = [];
$url_recipients = [];
@ -117,6 +100,13 @@ class Notifier
$condition = ['uid' => $target_id, 'self' => false, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
$delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'addr', 'network', 'protocol', 'batch'], $condition);
} else {
$post = Post::selectFirst(['id'], ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
if (!DBA::isResult($post)) {
Logger::warning('Post not found', ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
return;
}
$target_id = $post['id'];
// find ancestors
$condition = ['id' => $target_id, 'visible' => true];
$target_item = Post::selectFirst(Item::DELIVER_FIELDLIST, $condition);

View file

@ -53,10 +53,10 @@ class RemoveContact {
}
if (DBStructure::existsTable('item')) {
do {
$items = Post::select(['item-id', 'post-user-id', 'uri-id', 'guid'], $condition, ['limit' => 100]);
$items = Post::select(['uri-id', 'guid', 'uid'], $condition, ['limit' => 100]);
while ($item = Post::fetch($items)) {
Logger::info('Delete removed contact item', ['id' => $item['item-id'], 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]);
DBA::delete('item', ['id' => $item['item-id']]);
Logger::info('Delete removed contact item', ['uri-id' => $item['uri-id'], 'uid', 'guid' => $item['guid']]);
DBA::delete('item', ['uri-id' => $item['uri-id'], 'uid' => $item['uid']]);
}
DBA::close($items);
} while (Post::exists($condition));