The item table is now completely removed

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

View File

@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 2021.03-dev (Red Hot Poker)
-- DB_UPDATE_VERSION 1402
-- DB_UPDATE_VERSION 1403
-- ------------------------------------------
@ -676,127 +676,6 @@ CREATE TABLE IF NOT EXISTS `intro` (
FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
--
-- TABLE item
--
CREATE TABLE IF NOT EXISTS `item` (
`id` int unsigned NOT NULL auto_increment,
`guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this item',
`uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the item uri',
`parent` int unsigned COMMENT 'item.id of the parent to this item if it is a reply of some form; otherwise this must be set to the id of this item',
`parent-uri` varchar(255) NOT NULL DEFAULT '' COMMENT 'uri of the top-level parent to this item',
`parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the top-level parent uri',
`thr-parent` varchar(255) NOT NULL DEFAULT '' COMMENT 'If the parent of this item is not the top-level item in the conversation, the uri of the immediate parent; otherwise set to parent-uri',
`thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation timestamp.',
`edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last edit (default is created)',
`commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last comment/reply to this item',
`received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime',
`changed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date that something in the conversation changed, indicating clients should fetch the conversation again',
`gravity` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
`network` char(4) NOT NULL DEFAULT '' COMMENT 'Network from where the item comes from',
`owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
`author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
`causer-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
`vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
`extid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)',
`global` boolean NOT NULL DEFAULT '0' COMMENT '',
`private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
`visible` boolean NOT NULL DEFAULT '0' COMMENT '',
`deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been deleted',
`uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id which owns this copy of the item',
`contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
`unseen` boolean NOT NULL DEFAULT '1' COMMENT 'item has not been seen',
`origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
`psid` int unsigned COMMENT 'ID of the permission set of this post',
`starred` boolean NOT NULL DEFAULT '0' COMMENT 'item has been favourited',
`wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
`pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
`forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
`event-id` int unsigned COMMENT 'Used to link to the event.id',
`mention` boolean NOT NULL DEFAULT '0' COMMENT 'The owner of this item was mentioned in it',
`bookmark` boolean COMMENT 'Deprecated',
`type` varchar(20) COMMENT 'Deprecated',
`moderated` boolean NOT NULL DEFAULT '0' COMMENT 'Deprecated',
`resource-id` varchar(32) COMMENT 'Deprecated',
`uri-hash` varchar(80) COMMENT 'Deprecated',
`iaid` int unsigned COMMENT 'Deprecated',
`icid` int unsigned COMMENT 'Deprecated',
`attach` mediumtext COMMENT 'Deprecated',
`allow_cid` mediumtext COMMENT 'Deprecated',
`allow_gid` mediumtext COMMENT 'Deprecated',
`deny_cid` mediumtext COMMENT 'Deprecated',
`deny_gid` mediumtext COMMENT 'Deprecated',
`postopts` text COMMENT 'Deprecated',
`inform` mediumtext COMMENT 'Deprecated',
`file` mediumtext COMMENT 'Deprecated',
`location` varchar(255) COMMENT 'Deprecated',
`coord` varchar(255) COMMENT 'Deprecated',
`tag` mediumtext COMMENT 'Deprecated',
`plink` varchar(255) COMMENT 'Deprecated',
`title` varchar(255) COMMENT 'Deprecated',
`content-warning` varchar(255) COMMENT 'Deprecated',
`body` mediumtext COMMENT 'Deprecated',
`app` varchar(255) COMMENT 'Deprecated',
`verb` varchar(100) COMMENT 'Deprecated',
`object-type` varchar(100) COMMENT 'Deprecated',
`object` text COMMENT 'Deprecated',
`target-type` varchar(100) COMMENT 'Deprecated',
`target` text COMMENT 'Deprecated',
`author-name` varchar(255) COMMENT 'Deprecated',
`author-link` varchar(255) COMMENT 'Deprecated',
`author-avatar` varchar(255) COMMENT 'Deprecated',
`owner-name` varchar(255) COMMENT 'Deprecated',
`owner-link` varchar(255) COMMENT 'Deprecated',
`owner-avatar` varchar(255) COMMENT 'Deprecated',
`rendered-hash` varchar(32) COMMENT 'Deprecated',
`rendered-html` mediumtext COMMENT 'Deprecated',
PRIMARY KEY(`id`),
INDEX `guid` (`guid`(191)),
INDEX `uri` (`uri`(191)),
INDEX `parent` (`parent`),
INDEX `parent-uri` (`parent-uri`(191)),
INDEX `extid` (`extid`(191)),
INDEX `uid_id` (`uid`,`id`),
INDEX `uid_contactid_id` (`uid`,`contact-id`,`id`),
INDEX `uid_received` (`uid`,`received`),
INDEX `uid_commented` (`uid`,`commented`),
INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`),
INDEX `uid_network_received` (`uid`,`network`,`received`),
INDEX `uid_network_commented` (`uid`,`network`,`commented`),
INDEX `uid_thrparent` (`uid`,`thr-parent`(190)),
INDEX `uid_parenturi` (`uid`,`parent-uri`(190)),
INDEX `uid_contactid_received` (`uid`,`contact-id`,`received`),
INDEX `authorid_received` (`author-id`,`received`),
INDEX `ownerid` (`owner-id`),
INDEX `contact-id` (`contact-id`),
INDEX `uid_uri` (`uid`,`uri`(190)),
INDEX `resource-id` (`resource-id`),
INDEX `deleted_changed` (`deleted`,`changed`),
INDEX `uid_wall_changed` (`uid`,`wall`,`changed`),
INDEX `uid_unseen_wall` (`uid`,`unseen`,`wall`),
INDEX `mention_uid_id` (`mention`,`uid`,`id`),
INDEX `uid_eventid` (`uid`,`event-id`),
INDEX `vid` (`vid`),
INDEX `psid_wall` (`psid`,`wall`),
INDEX `uri-id` (`uri-id`),
INDEX `parent-uri-id` (`parent-uri-id`),
INDEX `thr-parent-id` (`thr-parent-id`),
INDEX `causer-id` (`causer-id`),
FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Structure for all posts';
--
-- TABLE locks
--
@ -1587,7 +1466,6 @@ CREATE TABLE IF NOT EXISTS `workerqueue` (
DROP VIEW IF EXISTS `post-view`;
CREATE VIEW `post-view` AS SELECT
`post-user`.`id` AS `id`,
`item`.`id` AS `item-id`,
`post-user`.`id` AS `post-user-id`,
`post-user`.`uid` AS `uid`,
`parent-post`.`id` AS `parent`,
@ -1722,23 +1600,22 @@ CREATE VIEW `post-view` AS SELECT
`parent-post-author`.`network` AS `parent-author-network`
FROM `post-user`
STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`
LEFT JOIN `item` ON `item`.`uri-id` = `post-user`.`uri-id` AND `item`.`uid` = `post-user`.`uid`
INNER JOIN `contact` ON `contact`.`id` = `post-user`.`contact-id`
INNER JOIN `contact` AS `author` ON `author`.`id` = `post-user`.`author-id`
INNER JOIN `contact` AS `owner` ON `owner`.`id` = `post-user`.`owner-id`
INNER JOIN `contact` AS `causer` ON `causer`.`id` = `post-user`.`causer-id`
INNER JOIN `item-uri` ON `item-uri`.`id` = `post-user`.`uri-id`
INNER JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
INNER JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
LEFT JOIN `contact` ON `contact`.`id` = `post-user`.`contact-id`
LEFT JOIN `contact` AS `author` ON `author`.`id` = `post-user`.`author-id`
LEFT JOIN `contact` AS `owner` ON `owner`.`id` = `post-user`.`owner-id`
LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-user`.`causer-id`
LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-user`.`uri-id`
LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
INNER JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-user`.`uri-id`
LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-user`.`uri-id`
LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-user`.`uri-id` AND `post-user`.`origin`
LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-user`.`psid`
LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
INNER JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
--
-- VIEW post-thread-view
@ -1746,7 +1623,6 @@ CREATE VIEW `post-view` AS SELECT
DROP VIEW IF EXISTS `post-thread-view`;
CREATE VIEW `post-thread-view` AS SELECT
`post-user`.`id` AS `id`,
`item`.`id` AS `item-id`,
`post-user`.`id` AS `post-user-id`,
`post-thread-user`.`uid` AS `uid`,
`parent-post`.`id` AS `parent`,
@ -1881,23 +1757,22 @@ CREATE VIEW `post-thread-view` AS SELECT
`parent-post-author`.`network` AS `parent-author-network`
FROM `post-thread-user`
INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
LEFT JOIN `item` ON `item`.`uri-id` = `post-thread-user`.`uri-id` AND `item`.`uid` = `post-thread-user`.`uid`
INNER JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
INNER JOIN `contact` AS `author` ON `author`.`id` = `post-thread-user`.`author-id`
INNER JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread-user`.`owner-id`
INNER JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread-user`.`causer-id`
INNER JOIN `item-uri` ON `item-uri`.`id` = `post-user`.`uri-id`
INNER JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
INNER JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
LEFT JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
LEFT JOIN `contact` AS `author` ON `author`.`id` = `post-thread-user`.`author-id`
LEFT JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread-user`.`owner-id`
LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread-user`.`causer-id`
LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-thread-user`.`uri-id`
LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
INNER JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread-user`.`uri-id`
LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread-user`.`uri-id`
LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-thread-user`.`uri-id` AND `post-thread-user`.`origin`
LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-thread-user`.`psid`
LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
INNER JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-thread-user`.`uid`
LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
--
-- VIEW category-view

View File

@ -78,7 +78,7 @@ class DBStructure
return;
}
$old_tables = ['fserver', 'gcign', 'gcontact', 'gcontact-relation', 'gfollower' ,'glink', 'item-delivery-data',
$old_tables = ['fserver', 'gcign', 'gcontact', 'gcontact-relation', 'gfollower' ,'glink', 'item', 'item-delivery-data',
'item-activity', 'item-content', 'item_id', 'participation', 'poll', 'poll_result', 'queue', 'retriever_rule',
'sign', 'spam', 'term', 'thread', 'user-item'];

View File

@ -229,7 +229,7 @@ class UserNotification
return;
}
Logger::info('Set notification', ['iid' => $item['id'], 'uri-id' => $item['uri-id'], 'uid' => $uid, 'notification-type' => $notification_type]);
Logger::info('Set notification', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'notification-type' => $notification_type]);
$fields = ['notification-type' => $notification_type];
Post\User::update($item['uri-id'], $uid, $fields);

View File

@ -1143,7 +1143,7 @@ class Processor
$implicit_mentions = [];
if (empty($parent_author['url'])) {
Logger::notice('Author public contact unknown.', ['author-link' => $parent['author-link'], 'item-id' => $parent['id']]);
Logger::notice('Author public contact unknown.', ['author-link' => $parent['author-link'], 'parent-id' => $parent['id']]);
} else {
$implicit_mentions[] = $parent_author['url'];
$implicit_mentions[] = $parent_author['nurl'];

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));

View File

@ -55,7 +55,7 @@
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1402);
define('DB_UPDATE_VERSION', 1403);
}
return [
@ -743,123 +743,6 @@ return [
"uid" => ["uid"],
]
],
"item" => [
"comment" => "Structure for all posts",
"fields" => [
"id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"],
"guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this item"],
"uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
"parent" => ["type" => "int unsigned", "relation" => ["item" => "id"], "comment" => "item.id of the parent to this item if it is a reply of some form; otherwise this must be set to the id of this item"],
"parent-uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "uri of the top-level parent to this item"],
"parent-uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table that contains the top-level parent uri"],
"thr-parent" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "If the parent of this item is not the top-level item in the conversation, the uri of the immediate parent; otherwise set to parent-uri"],
"thr-parent-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table that contains the thread parent uri"],
"created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Creation timestamp."],
"edited" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date of last edit (default is created)"],
"commented" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date of last comment/reply to this item"],
"received" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "datetime"],
"changed" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date that something in the conversation changed, indicating clients should fetch the conversation again"],
"gravity" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
"network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network from where the item comes from"],
"owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the owner of this item"],
"author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the author of this item"],
"causer-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the contact that caused the item creation"],
"vid" => ["type" => "smallint unsigned", "foreign" => ["verb" => "id", "on delete" => "restrict"], "comment" => "Id of the verb table entry that contains the activity verbs"],
"extid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
"global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"private" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "0=public, 1=private, 2=unlisted"],
"visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been deleted"],
// Part of "post-user". Will be deprecated in a later step
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "Owner id which owns this copy of the item"],
"contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id"], "comment" => "contact.id"],
"unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "item has not been seen"],
"origin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item originated at this site"],
"psid" => ["type" => "int unsigned", "foreign" => ["permissionset" => "id", "on delete" => "restrict"], "comment" => "ID of the permission set of this post"],
// Part of "post-thread-user". Will be deprecated in a later step
"starred" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been favourited"],
"wall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "This item was posted to the wall of uid"],
"pubmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
// It has to be decided whether these fields belong to the user or the structure
"event-id" => ["type" => "int unsigned", "relation" => ["event" => "id"], "comment" => "Used to link to the event.id"],
// Check deprecation status
"mention" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "The owner of this item was mentioned in it"],
// Deprecated fields. Will not be transferred to the "post" table
"bookmark" => ["type" => "boolean", "comment" => "Deprecated"],
"type" => ["type" => "varchar(20)", "comment" => "Deprecated"],
"moderated" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Deprecated"],
"resource-id" => ["type" => "varchar(32)", "comment" => "Deprecated"],
"uri-hash" => ["type" => "varchar(80)", "comment" => "Deprecated"],
"iaid" => ["type" => "int unsigned", "comment" => "Deprecated"],
"icid" => ["type" => "int unsigned", "comment" => "Deprecated"],
"attach" => ["type" => "mediumtext", "comment" => "Deprecated"],
"allow_cid" => ["type" => "mediumtext", "comment" => "Deprecated"],
"allow_gid" => ["type" => "mediumtext", "comment" => "Deprecated"],
"deny_cid" => ["type" => "mediumtext", "comment" => "Deprecated"],
"deny_gid" => ["type" => "mediumtext", "comment" => "Deprecated"],
"postopts" => ["type" => "text", "comment" => "Deprecated"],
"inform" => ["type" => "mediumtext", "comment" => "Deprecated"],
"file" => ["type" => "mediumtext", "comment" => "Deprecated"],
"location" => ["type" => "varchar(255)", "comment" => "Deprecated"],
"coord" => ["type" => "varchar(255)", "comment" => "Deprecated"],
"tag" => ["type" => "mediumtext", "comment" => "Deprecated"],
"plink" => ["type" => "varchar(255)", "comment" => "Deprecated"],
"title" => ["type" => "varchar(255)", "comment" => "Deprecated"],
"content-warning" => ["type" => "varchar(255)", "comment" => "Deprecated"],
"body" => ["type" => "mediumtext", "comment" => "Deprecated"],
"app" => ["type" => "varchar(255)", "comment" => "Deprecated"],
"verb" => ["type" => "varchar(100)", "comment" => "Deprecated"],
"object-type" => ["type" => "varchar(100)", "comment" => "Deprecated"],
"object" => ["type" => "text", "comment" => "Deprecated"],
"target-type" => ["type" => "varchar(100)", "comment" => "Deprecated"],
"target" => ["type" => "text", "comment" => "Deprecated"],
"author-name" => ["type" => "varchar(255)", "comment" => "Deprecated"],
"author-link" => ["type" => "varchar(255)", "comment" => "Deprecated"],
"author-avatar" => ["type" => "varchar(255)", "comment" => "Deprecated"],
"owner-name" => ["type" => "varchar(255)", "comment" => "Deprecated"],
"owner-link" => ["type" => "varchar(255)", "comment" => "Deprecated"],
"owner-avatar" => ["type" => "varchar(255)", "comment" => "Deprecated"],
"rendered-hash" => ["type" => "varchar(32)", "comment" => "Deprecated"],
"rendered-html" => ["type" => "mediumtext", "comment" => "Deprecated"],
],
"indexes" => [
"PRIMARY" => ["id"],
"guid" => ["guid(191)"],
"uri" => ["uri(191)"],
"parent" => ["parent"],
"parent-uri" => ["parent-uri(191)"],
"extid" => ["extid(191)"],
"uid_id" => ["uid", "id"],
"uid_contactid_id" => ["uid", "contact-id", "id"],
"uid_received" => ["uid", "received"],
"uid_commented" => ["uid", "commented"],
"uid_unseen_contactid" => ["uid", "unseen", "contact-id"],
"uid_network_received" => ["uid", "network", "received"],
"uid_network_commented" => ["uid", "network", "commented"],
"uid_thrparent" => ["uid", "thr-parent(190)"],
"uid_parenturi" => ["uid", "parent-uri(190)"],
"uid_contactid_received" => ["uid", "contact-id", "received"],
"authorid_received" => ["author-id", "received"],
"ownerid" => ["owner-id"],
"contact-id" => ["contact-id"],
"uid_uri" => ["uid", "uri(190)"],
"resource-id" => ["resource-id"],
"deleted_changed" => ["deleted", "changed"],
"uid_wall_changed" => ["uid", "wall", "changed"],
"uid_unseen_wall" => ["uid", "unseen", "wall"],
"mention_uid_id" => ["mention", "uid", "id"],
"uid_eventid" => ["uid", "event-id"],
"vid" => ["vid"],
"psid_wall" => ["psid", "wall"],
"uri-id" => ["uri-id"],
"parent-uri-id" => ["parent-uri-id"],
"thr-parent-id" => ["thr-parent-id"],
"causer-id" => ["causer-id"],
]
],
"locks" => [
"comment" => "",
"fields" => [

View File

@ -40,7 +40,6 @@
"post-view" => [
"fields" => [
"id" => ["post-user", "id"],
"item-id" => ["item", "id"],
"post-user-id" => ["post-user", "id"],
"uid" => ["post-user", "uid"],
"parent" => ["parent-post", "id"],
@ -176,28 +175,26 @@
],
"query" => "FROM `post-user`
STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`
LEFT JOIN `item` ON `item`.`uri-id` = `post-user`.`uri-id` AND `item`.`uid` = `post-user`.`uid`
INNER JOIN `contact` ON `contact`.`id` = `post-user`.`contact-id`
INNER JOIN `contact` AS `author` ON `author`.`id` = `post-user`.`author-id`
INNER JOIN `contact` AS `owner` ON `owner`.`id` = `post-user`.`owner-id`
INNER JOIN `contact` AS `causer` ON `causer`.`id` = `post-user`.`causer-id`
INNER JOIN `item-uri` ON `item-uri`.`id` = `post-user`.`uri-id`
INNER JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
INNER JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
LEFT JOIN `contact` ON `contact`.`id` = `post-user`.`contact-id`
LEFT JOIN `contact` AS `author` ON `author`.`id` = `post-user`.`author-id`
LEFT JOIN `contact` AS `owner` ON `owner`.`id` = `post-user`.`owner-id`
LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-user`.`causer-id`
LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-user`.`uri-id`
LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
INNER JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-user`.`uri-id`
LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-user`.`uri-id`
LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-user`.`uri-id` AND `post-user`.`origin`
LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-user`.`psid`
LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
INNER JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`"
LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`"
],
"post-thread-view" => [
"fields" => [
"id" => ["post-user", "id"],
"item-id" => ["item", "id"],
"post-user-id" => ["post-user", "id"],
"uid" => ["post-thread-user", "uid"],
"parent" => ["parent-post", "id"],
@ -333,23 +330,22 @@
],
"query" => "FROM `post-thread-user`
INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
LEFT JOIN `item` ON `item`.`uri-id` = `post-thread-user`.`uri-id` AND `item`.`uid` = `post-thread-user`.`uid`
INNER JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
INNER JOIN `contact` AS `author` ON `author`.`id` = `post-thread-user`.`author-id`
INNER JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread-user`.`owner-id`
INNER JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread-user`.`causer-id`
INNER JOIN `item-uri` ON `item-uri`.`id` = `post-user`.`uri-id`
INNER JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
INNER JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
LEFT JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
LEFT JOIN `contact` AS `author` ON `author`.`id` = `post-thread-user`.`author-id`
LEFT JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread-user`.`owner-id`
LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread-user`.`causer-id`
LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-thread-user`.`uri-id`
LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
INNER JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread-user`.`uri-id`
LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread-user`.`uri-id`
LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-thread-user`.`uri-id` AND `post-thread-user`.`origin`
LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-thread-user`.`psid`
LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
INNER JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`"
LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-thread-user`.`uid`
LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`"
],
"category-view" => [
"fields" => [

View File

@ -817,3 +817,62 @@ function update_1400()
return Update::SUCCESS;
}
function update_1403()
{
$tasks = DBA::select('workerqueue', ['id', 'command', 'parameter'], ['command' => ['notifier', 'delivery', 'apdelivery', 'done' => false]]);
while ($task = DBA::fetch($tasks)) {
$parameters = json_decode($task['parameter'], true);
if (in_array($parameters[0], [Delivery::MAIL, Delivery::SUGGESTION, Delivery::REMOVAL, Delivery::RELOCATION])) {
continue;
}
switch (strtolower($task['command'])) {
case 'notifier':
if (count($parameters) == 3) {
continue 2;
}
$item = DBA::selectFirst('item', ['uid', 'uri-id'], ['id' => $parameters[1]]);
if (!DBA::isResult($item)) {
continue 2;
}
$parameters[1] = $item['uri-id'];
$parameters[2] = $item['uid'];
break;
case 'delivery':
if (count($parameters) == 4) {
continue 2;
}
$item = DBA::selectFirst('item', ['uid', 'uri-id'], ['id' => $parameters[1]]);
if (!DBA::isResult($item)) {
continue 2;
}
$parameters[1] = $item['uri-id'];
$parameters[3] = $item['uid'];
break;
case 'apdelivery':
if (count($parameters) == 6) {
continue 2;
}
if (empty($parameters[4])) {
$parameters[4] = [];
}
$item = DBA::selectFirst('item', ['uri-id'], ['id' => $parameters[1]]);
if (!DBA::isResult($item)) {
continue 2;
}
$parameters[5] = $item['uri-id'];
break;
default:
continue 2;
}
DBA::update('workerqueue', ['parameter' => json_encode($parameters)], ['id' => $task['id']]);
}
return Update::SUCCESS;
}