From ce6ad1aa73885196ce5393a910d1b57774a940d4 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 13 Feb 2021 19:56:03 +0000 Subject: [PATCH 01/25] Get rid of the "item" table, enhanced "post" tables --- database.sql | 286 +++++++++++++++++++---- mod/item.php | 14 +- src/Content/Widget/TagCloud.php | 2 +- src/Factory/Api/Mastodon/Status.php | 4 +- src/Model/Contact.php | 2 +- src/Model/Item.php | 58 +++-- src/Model/Post.php | 81 ++++++- src/Module/Conversation/Network.php | 4 +- src/Module/Profile/Status.php | 2 +- src/Module/Search/Filed.php | 3 +- src/Module/Search/Index.php | 2 +- src/Module/Update/Profile.php | 2 +- src/Protocol/ActivityPub/Processor.php | 5 +- src/Protocol/ActivityPub/Receiver.php | 2 +- src/Protocol/ActivityPub/Transmitter.php | 12 +- src/Protocol/Feed.php | 6 +- src/Worker/Delivery.php | 5 +- src/Worker/Notifier.php | 10 +- src/Worker/RemoveContact.php | 9 +- static/dbstructure.config.php | 102 +++++++- static/dbview.config.php | 231 +++++++++--------- tests/datasets/api.fixture.php | 81 +++++++ update.php | 48 ++++ 23 files changed, 736 insertions(+), 235 deletions(-) diff --git a/database.sql b/database.sql index 9d6adbb7d..52a1d7eeb 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 2021.03-dev (Red Hot Poker) --- DB_UPDATE_VERSION 1399 +-- DB_UPDATE_VERSION 1400 -- ------------------------------------------ @@ -705,7 +705,6 @@ CREATE TABLE IF NOT EXISTS `item` ( `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 '', - `moderated` 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', @@ -717,9 +716,10 @@ CREATE TABLE IF NOT EXISTS `item` ( `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', - `type` varchar(20) COMMENT '', - `bookmark` boolean COMMENT '', `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', @@ -1026,6 +1026,43 @@ CREATE TABLE IF NOT EXISTS `photo` ( FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='photo storage'; +-- +-- TABLE post +-- +CREATE TABLE IF NOT EXISTS `post` ( + `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri', + `parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the 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)', + `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime', + `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', + `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)', + `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs', + `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted', + `global` boolean NOT NULL DEFAULT '0' COMMENT '', + `visible` boolean NOT NULL DEFAULT '0' COMMENT '', + `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been marked for deletion', + PRIMARY KEY(`uri-id`), + INDEX `parent-uri-id` (`parent-uri-id`), + INDEX `thr-parent-id` (`thr-parent-id`), + INDEX `owner-id` (`owner-id`), + INDEX `author-id` (`author-id`), + INDEX `causer-id` (`causer-id`), + INDEX `vid` (`vid`), + 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 +) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Structure for all posts'; + -- -- TABLE post-category -- @@ -1160,9 +1197,11 @@ CREATE TABLE IF NOT EXISTS `post-user` ( `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item', `protocol` tinyint unsigned COMMENT 'Protocol used to deliver the item for this user', `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id', + `event-id` int unsigned COMMENT 'Used to link to the event.id', `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'post has not been seen', `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide the post from the user', `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '', + `wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid', `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site', `psid` int unsigned COMMENT 'ID of the permission set of this post', PRIMARY KEY(`id`), @@ -1171,9 +1210,12 @@ CREATE TABLE IF NOT EXISTS `post-user` ( INDEX `contact-id` (`contact-id`), INDEX `psid` (`psid`), INDEX `uid_hidden` (`uid`,`hidden`), + INDEX `event-id` (`event-id`), + INDEX `uid_wall` (`uid`,`wall`), FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE, 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 (`event-id`) REFERENCES `event` (`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='User specific post data'; @@ -1486,7 +1528,6 @@ CREATE VIEW `post-view` AS SELECT `item`.`thr-parent` AS `thr-parent`, `item`.`thr-parent-id` AS `thr-parent-id`, `item`.`guid` AS `guid`, - `item`.`type` AS `type`, `item`.`wall` AS `wall`, `item`.`gravity` AS `gravity`, `item`.`extid` AS `extid`, @@ -1498,10 +1539,8 @@ CREATE VIEW `post-view` AS SELECT `item`.`post-type` AS `post-type`, `item`.`private` AS `private`, `item`.`pubmail` AS `pubmail`, - `item`.`moderated` AS `moderated`, `item`.`visible` AS `visible`, `item`.`starred` AS `starred`, - `item`.`bookmark` AS `bookmark`, `item`.`unseen` AS `unseen`, `item`.`deleted` AS `deleted`, `item`.`origin` AS `origin`, @@ -1624,6 +1663,164 @@ CREATE VIEW `post-view` AS SELECT STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`uri-id` = `item`.`parent-uri-id` AND `parent-item`.`uid` = `item`.`uid` STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id`; +-- +-- VIEW post-view2 +-- +DROP VIEW IF EXISTS `post-view2`; +CREATE VIEW `post-view2` AS SELECT + `item`.`id` AS `id`, + `item`.`id` AS `item_id`, + `post-user`.`id` AS `post-user-id`, + `post-user`.`uid` AS `uid`, + `item`.`parent` AS `parent`, + `item-uri`.`uri` AS `uri`, + `post`.`uri-id` AS `uri-id`, + `parent-item-uri`.`uri` AS `parent-uri`, + `post`.`parent-uri-id` AS `parent-uri-id`, + `thr-parent-item-uri`.`uri` AS `thr-parent`, + `post`.`thr-parent-id` AS `thr-parent-id`, + `item-uri`.`guid` AS `guid`, + `post-user`.`wall` AS `wall`, + `post`.`gravity` AS `gravity`, + `item`.`extid` AS `extid`, + `post`.`created` AS `created`, + `post`.`edited` AS `edited`, + `post-thread`.`commented` AS `commented`, + `post`.`received` AS `received`, + `post-thread`.`changed` AS `changed`, + `post`.`post-type` AS `post-type`, + `post`.`private` AS `private`, + `post-thread-user`.`pubmail` AS `pubmail`, + `post`.`visible` AS `visible`, + `post-thread-user`.`starred` AS `starred`, + `post-user`.`unseen` AS `unseen`, + `post`.`deleted` AS `deleted`, + `post-user`.`origin` AS `origin`, + `post-thread-user`.`forum_mode` AS `forum_mode`, + `post-thread-user`.`mention` AS `mention`, + `post`.`global` AS `global`, + `post`.`network` AS `network`, + `post`.`vid` AS `vid`, + `post-user`.`psid` AS `psid`, + IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`, + `post-content`.`title` AS `title`, + `post-content`.`content-warning` AS `content-warning`, + `post-content`.`raw-body` AS `raw-body`, + `post-content`.`body` AS `body`, + `post-content`.`rendered-hash` AS `rendered-hash`, + `post-content`.`rendered-html` AS `rendered-html`, + `post-content`.`language` AS `language`, + `post-content`.`plink` AS `plink`, + `post-content`.`location` AS `location`, + `post-content`.`coord` AS `coord`, + `post-content`.`app` AS `app`, + `post-content`.`object-type` AS `object-type`, + `post-content`.`object` AS `object`, + `post-content`.`target-type` AS `target-type`, + `post-content`.`target` AS `target`, + `post-content`.`resource-id` AS `resource-id`, + `post-user`.`contact-id` AS `contact-id`, + `contact`.`url` AS `contact-link`, + `contact`.`addr` AS `contact-addr`, + `contact`.`name` AS `contact-name`, + `contact`.`nick` AS `contact-nick`, + `contact`.`thumb` AS `contact-avatar`, + `contact`.`network` AS `contact-network`, + `contact`.`blocked` AS `contact-blocked`, + `contact`.`hidden` AS `contact-hidden`, + `contact`.`readonly` AS `contact-readonly`, + `contact`.`archive` AS `contact-archive`, + `contact`.`pending` AS `contact-pending`, + `contact`.`rel` AS `contact-rel`, + `contact`.`uid` AS `contact-uid`, + `contact`.`contact-type` AS `contact-contact-type`, + IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`, + `contact`.`self` AS `self`, + `contact`.`id` AS `cid`, + `contact`.`alias` AS `alias`, + `contact`.`photo` AS `photo`, + `contact`.`name-date` AS `name-date`, + `contact`.`uri-date` AS `uri-date`, + `contact`.`avatar-date` AS `avatar-date`, + `contact`.`thumb` AS `thumb`, + `contact`.`dfrn-id` AS `dfrn-id`, + `post`.`author-id` AS `author-id`, + `author`.`url` AS `author-link`, + `author`.`addr` AS `author-addr`, + IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`, + `author`.`nick` AS `author-nick`, + IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`, + `author`.`network` AS `author-network`, + `author`.`blocked` AS `author-blocked`, + `author`.`hidden` AS `author-hidden`, + `post`.`owner-id` AS `owner-id`, + `owner`.`url` AS `owner-link`, + `owner`.`addr` AS `owner-addr`, + IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`, + `owner`.`nick` AS `owner-nick`, + IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`, + `owner`.`network` AS `owner-network`, + `owner`.`blocked` AS `owner-blocked`, + `owner`.`hidden` AS `owner-hidden`, + `post`.`causer-id` AS `causer-id`, + `causer`.`url` AS `causer-link`, + `causer`.`addr` AS `causer-addr`, + `causer`.`name` AS `causer-name`, + `causer`.`nick` AS `causer-nick`, + `causer`.`thumb` AS `causer-avatar`, + `causer`.`network` AS `causer-network`, + `causer`.`blocked` AS `causer-blocked`, + `causer`.`hidden` AS `causer-hidden`, + `causer`.`contact-type` AS `causer-contact-type`, + `post-delivery-data`.`postopts` AS `postopts`, + `post-delivery-data`.`inform` AS `inform`, + `post-delivery-data`.`queue_count` AS `delivery_queue_count`, + `post-delivery-data`.`queue_done` AS `delivery_queue_done`, + `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`, + IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`, + IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`, + IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`, + IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`, + `post-user`.`event-id` AS `event-id`, + `event`.`created` AS `event-created`, + `event`.`edited` AS `event-edited`, + `event`.`start` AS `event-start`, + `event`.`finish` AS `event-finish`, + `event`.`summary` AS `event-summary`, + `event`.`desc` AS `event-desc`, + `event`.`location` AS `event-location`, + `event`.`type` AS `event-type`, + `event`.`nofinish` AS `event-nofinish`, + `event`.`adjust` AS `event-adjust`, + `event`.`ignore` AS `event-ignore`, + `diaspora-interaction`.`interaction` AS `signed_text`, + `parent-item-uri`.`guid` AS `parent-guid`, + `parent-post`.`network` AS `parent-network`, + `parent-post`.`author-id` AS `parent-author-id`, + `parent-item-author`.`url` AS `parent-author-link`, + `parent-item-author`.`name` AS `parent-author-name`, + `parent-item-author`.`network` AS `parent-author-network` + FROM `post` + STRAIGHT_JOIN `post-user` ON `post-user`.`uri-id` = `post`.`uri-id` + STRAIGHT_JOIN `post-thread` ON `post-thread`.`uri-id` = `post`.`parent-uri-id` + STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid` + STRAIGHT_JOIN `item` ON `item`.`uri-id` = `post`.`uri-id` AND `item`.`uid` = `post-user`.`uid` + LEFT JOIN `item-uri` ON `item-uri`.`id` = `post`.`uri-id` + LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id` + LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id` + LEFT JOIN `contact` ON `contact`.`id` = `post-user`.`contact-id` + LEFT JOIN `contact` AS `author` ON `author`.`id` = `post`.`author-id` + LEFT JOIN `contact` AS `owner` ON `owner`.`id` = `post`.`owner-id` + LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post`.`causer-id` + LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid` + LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id` + LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post`.`uri-id` + LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post`.`uri-id` + LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post`.`uri-id` + LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-user`.`psid` + LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id` + LEFT JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-post`.`author-id`; + -- -- VIEW post-thread-view -- @@ -1632,42 +1829,40 @@ CREATE VIEW `post-thread-view` AS SELECT `item`.`id` AS `id`, `item`.`id` AS `iid`, `item`.`id` AS `item_id`, + `post-thread-user`.`post-user-id` AS `post-user-id`, `post-thread-user`.`uid` AS `uid`, `item`.`parent` AS `parent`, - `item`.`uri` AS `uri`, + `item-uri`.`uri` AS `uri`, `post-thread`.`uri-id` AS `uri-id`, - `item`.`parent-uri` AS `parent-uri`, - `item`.`parent-uri-id` AS `parent-uri-id`, - `item`.`thr-parent` AS `thr-parent`, - `item`.`thr-parent-id` AS `thr-parent-id`, - `item`.`guid` AS `guid`, - `item`.`type` AS `type`, + `parent-item-uri`.`uri` AS `parent-uri`, + `post`.`parent-uri-id` AS `parent-uri-id`, + `thr-parent-item-uri`.`uri` AS `thr-parent`, + `post`.`thr-parent-id` AS `thr-parent-id`, + `item-uri`.`guid` AS `guid`, `post-thread-user`.`wall` AS `wall`, - `item`.`gravity` AS `gravity`, + `post`.`gravity` AS `gravity`, `item`.`extid` AS `extid`, `post-thread`.`created` AS `created`, - `item`.`edited` AS `edited`, + `post`.`edited` AS `edited`, `post-thread`.`commented` AS `commented`, `post-thread`.`received` AS `received`, `post-thread`.`changed` AS `changed`, - `item`.`post-type` AS `post-type`, - `item`.`private` AS `private`, + `post`.`post-type` AS `post-type`, + `post`.`private` AS `private`, `post-thread-user`.`pubmail` AS `pubmail`, - `item`.`moderated` AS `moderated`, `post-thread-user`.`ignored` AS `ignored`, - `item`.`visible` AS `visible`, + `post`.`visible` AS `visible`, `post-thread-user`.`starred` AS `starred`, - `item`.`bookmark` AS `bookmark`, `post-thread-user`.`unseen` AS `unseen`, - `item`.`deleted` AS `deleted`, + `post`.`deleted` AS `deleted`, `post-thread-user`.`origin` AS `origin`, `post-thread-user`.`forum_mode` AS `forum_mode`, - `item`.`mention` AS `mention`, - `item`.`global` AS `global`, + `post-thread-user`.`mention` AS `mention`, + `post`.`global` AS `global`, `post-thread`.`network` AS `network`, - `item`.`vid` AS `vid`, + `post`.`vid` AS `vid`, `post-thread-user`.`psid` AS `psid`, - IF (`item`.`vid` IS NULL, '', `verb`.`name`) AS `verb`, + IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`, `post-content`.`title` AS `title`, `post-content`.`content-warning` AS `content-warning`, `post-content`.`raw-body` AS `raw-body`, @@ -1699,7 +1894,7 @@ CREATE VIEW `post-thread-view` AS SELECT `contact`.`rel` AS `contact-rel`, `contact`.`uid` AS `contact-uid`, `contact`.`contact-type` AS `contact-contact-type`, - IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`, + IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`, `contact`.`self` AS `self`, `contact`.`id` AS `cid`, `contact`.`alias` AS `alias`, @@ -1727,7 +1922,7 @@ CREATE VIEW `post-thread-view` AS SELECT `owner`.`network` AS `owner-network`, `owner`.`blocked` AS `owner-blocked`, `owner`.`hidden` AS `owner-hidden`, - `item`.`causer-id` AS `causer-id`, + `post-thread`.`causer-id` AS `causer-id`, `causer`.`url` AS `causer-link`, `causer`.`addr` AS `causer-addr`, `causer`.`name` AS `causer-name`, @@ -1746,7 +1941,7 @@ CREATE VIEW `post-thread-view` AS SELECT IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`, IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`, IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`, - `item`.`event-id` AS `event-id`, + `post-user`.`event-id` AS `event-id`, `event`.`created` AS `event-created`, `event`.`edited` AS `event-edited`, `event`.`start` AS `event-start`, @@ -1759,27 +1954,32 @@ CREATE VIEW `post-thread-view` AS SELECT `event`.`adjust` AS `event-adjust`, `event`.`ignore` AS `event-ignore`, `diaspora-interaction`.`interaction` AS `signed_text`, - `parent-item`.`guid` AS `parent-guid`, - `parent-item`.`network` AS `parent-network`, - `parent-item`.`author-id` AS `parent-author-id`, + `parent-item-uri`.`guid` AS `parent-guid`, + `parent-post`.`network` AS `parent-network`, + `parent-post`.`author-id` AS `parent-author-id`, `parent-item-author`.`url` AS `parent-author-link`, `parent-item-author`.`name` AS `parent-author-name`, `parent-item-author`.`network` AS `parent-author-network` FROM `post-thread` STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-thread`.`uri-id` - STRAIGHT_JOIN `item` ON `item`.`uri-id` = `post-thread`.`uri-id` AND `item`.`uid` = `post-thread-user`.`uid` - STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id` - STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread`.`author-id` - STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread`.`owner-id` - STRAIGHT_JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread`.`causer-id` - LEFT JOIN `verb` ON `verb`.`id` = `item`.`vid` - LEFT JOIN `event` ON `event`.`id` = `item`.`event-id` + STRAIGHT_JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id` + STRAIGHT_JOIN `post` ON `post`.`uri-id` = `post-thread`.`uri-id` + LEFT JOIN `item-uri` ON `item-uri`.`id` = `post`.`uri-id` + LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id` + LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id` + LEFT JOIN `item` ON `item`.`uri-id` = `post-thread`.`uri-id` AND `item`.`uid` = `post-thread-user`.`uid` + LEFT JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id` + LEFT JOIN `contact` AS `author` ON `author`.`id` = `post-thread`.`author-id` + LEFT JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread`.`owner-id` + LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread`.`causer-id` + LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid` + LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id` LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread`.`uri-id` LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread`.`uri-id` LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-thread`.`uri-id` AND `post-thread-user`.`origin` LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-thread-user`.`psid` - STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent` - STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id`; + LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id` + LEFT JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-post`.`author-id`; -- -- VIEW category-view @@ -1842,7 +2042,7 @@ CREATE VIEW `network-item-view` AS SELECT LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `parent-item`.`uid` AND `author`.`cid` = `parent-item`.`author-id` LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `parent-item`.`uid` AND `owner`.`cid` = `parent-item`.`owner-id` LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `parent-item`.`owner-id` - WHERE `parent-item`.`visible` AND NOT `parent-item`.`deleted` AND NOT `parent-item`.`moderated` + WHERE `parent-item`.`visible` AND NOT `parent-item`.`deleted` AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`) AND (`post-user`.`hidden` IS NULL OR NOT `post-user`.`hidden`) AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`) @@ -1873,7 +2073,7 @@ CREATE VIEW `network-thread-view` AS SELECT LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread`.`author-id` LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread`.`owner-id` LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread`.`owner-id` - WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` + WHERE `item`.`visible` AND NOT `item`.`deleted` AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`) AND (`post-thread-user`.`hidden` IS NULL OR NOT `post-thread-user`.`hidden`) AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`) diff --git a/mod/item.php b/mod/item.php index 0b0479017..0c252cd6c 100644 --- a/mod/item.php +++ b/mod/item.php @@ -113,9 +113,9 @@ function item_post(App $a) { if ($parent_item_id || $thr_parent_uri) { if ($parent_item_id) { - $parent_item = Post::selectFirst([], ['id' => $parent_item_id]); + $parent_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $parent_item_id]); } elseif ($thr_parent_uri) { - $parent_item = Post::selectFirst([], ['uri' => $thr_parent_uri, 'uid' => $profile_uid]); + $parent_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['uri' => $thr_parent_uri, 'uid' => $profile_uid]); } // if this isn't the top-level parent of the conversation, find it @@ -125,7 +125,7 @@ function item_post(App $a) { $toplevel_item = $parent_item; if ($parent_item['gravity'] != GRAVITY_PARENT) { - $toplevel_item = Post::selectFirst([], ['id' => $toplevel_item['parent']]); + $toplevel_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $toplevel_item['parent']]); } } @@ -143,7 +143,7 @@ function item_post(App $a) { $stored = Item::storeForUserByUriId($toplevel_item['uri-id'], local_user()); Logger::info('Public item stored for user', ['uri-id' => $toplevel_item['uri-id'], 'uid' => $uid, 'stored' => $stored]); if ($stored) { - $toplevel_item = Post::selectFirst([], ['id' => $stored]); + $toplevel_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $stored]); } } @@ -462,7 +462,7 @@ function item_post(App $a) { /* * Next link in any attachment references we find in the post. */ - $match = false; + $match = []; /// @todo these lines should be moved to Model/Attach (Once it exists) if (!$preview && preg_match_all("/\[attachment\](.*?)\[\/attachment\]/", $body, $match)) { @@ -489,6 +489,7 @@ function item_post(App $a) { // embedded bookmark or attachment in post? set bookmark flag $data = BBCode::getAttachmentData($body); + $match = []; if ((preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $body, $match, PREG_SET_ORDER) || isset($data["type"])) && ($posttype != Item::PT_PERSONAL_NOTE)) { $posttype = Item::PT_PAGE; @@ -515,7 +516,7 @@ function item_post(App $a) { } $attachments = ''; - $match = false; + $match = []; if (preg_match_all('/(\[attachment\]([0-9]+)\[\/attachment\])/',$body,$match)) { foreach ($match[2] as $mtch) { @@ -603,7 +604,6 @@ function item_post(App $a) { $datarray['postopts'] = $postopts; $datarray['origin'] = $origin; - $datarray['moderated'] = false; $datarray['object'] = $object; /* diff --git a/src/Content/Widget/TagCloud.php b/src/Content/Widget/TagCloud.php index c582c3eb6..cd170c329 100644 --- a/src/Content/Widget/TagCloud.php +++ b/src/Content/Widget/TagCloud.php @@ -104,7 +104,7 @@ class TagCloud $tag_stmt = DBA::p("SELECT `name`, COUNT(`name`) AS `total` FROM `tag-search-view` LEFT JOIN `post-view` ON `tag-search-view`.`uri-id` = `post-view`.`uri-id` WHERE `tag-search-view`.`uid` = ? - AND `post-view`.`visible` AND NOT `post-view`.`deleted` AND NOT `post-view`.`moderated` + AND `post-view`.`visible` AND NOT `post-view`.`deleted` $sql_options GROUP BY `name` ORDER BY `total` DESC $limit", $uid diff --git a/src/Factory/Api/Mastodon/Status.php b/src/Factory/Api/Mastodon/Status.php index 6a3212c26..6f2bf2743 100644 --- a/src/Factory/Api/Mastodon/Status.php +++ b/src/Factory/Api/Mastodon/Status.php @@ -61,7 +61,9 @@ class Status extends BaseFactory */ public function createFromUriId(int $uriId, $uid = 0) { - $item = Post::selectFirst([], ['uri-id' => $uriId, 'uid' => $uid]); + $fields = ['uri-id', 'uid', 'author-id', 'starred', 'app', 'title', 'body', 'raw-body', 'created', + 'thr-parent-id', 'parent-author-id', 'language', 'uri', 'plink', 'private', 'vid', 'gravity']; + $item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => $uid]); if (!$item) { throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . 'not found' . ($uid ? ' for user ' . $uid : '.')); } diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 05c7fb61f..5a3f0aaef 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1343,7 +1343,7 @@ class Contact $o .= conversation($a, $items, 'contacts', $update, false, 'commented', local_user()); } else { - $items = Post::toArray(Post::selectForUser(local_user(), [], $condition, $params)); + $items = Post::toArray(Post::selectForUser(local_user(), Item::DISPLAY_FIELDLIST, $condition, $params)); $o .= conversation($a, $items, 'contact-posts', $update); } diff --git a/src/Model/Item.php b/src/Model/Item.php index 0b0885b56..6114457d6 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -83,7 +83,7 @@ class Item 'causer-id', 'causer-link', 'causer-name', 'causer-avatar', 'causer-contact-type', 'contact-id', 'contact-uid', 'contact-link', 'contact-name', 'contact-avatar', 'writable', 'self', 'cid', 'alias', - 'event-id', 'event-created', 'event-edited', 'event-start', 'event-finish', + 'event-created', 'event-edited', 'event-start', 'event-finish', 'event-summary', 'event-desc', 'event-location', 'event-type', 'event-nofinish', 'event-adjust', 'event-ignore', 'event-id', 'delivery_queue_count', 'delivery_queue_done', 'delivery_queue_failed' @@ -91,34 +91,38 @@ class Item // Field list that is used to deliver items via the protocols const DELIVER_FIELDLIST = ['uid', 'id', 'parent', 'uri-id', 'uri', 'thr-parent', 'parent-uri', 'guid', - 'parent-guid', 'created', 'edited', 'verb', 'object-type', 'object', 'target', - 'private', 'title', 'body', 'location', 'coord', 'app', - 'deleted', 'extid', 'post-type', 'gravity', + 'parent-guid', 'received', 'created', 'edited', 'verb', 'object-type', 'object', 'target', + 'private', 'title', 'body', 'raw-body', 'location', 'coord', 'app', + 'inform', 'deleted', 'extid', 'post-type', 'gravity', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', - 'author-id', 'author-link', 'owner-link', 'contact-uid', - 'signed_text', 'network']; + 'author-id', 'author-link', 'owner-id', 'owner-link', 'contact-uid', + 'signed_text', 'network', 'wall', 'contact-id', 'plink', 'forum_mode', 'origin', + 'thr-parent-id', 'parent-uri-id', 'postopts', 'pubmail', + 'event-created', 'event-edited', 'event-start', 'event-finish', + 'event-summary', 'event-desc', 'event-location', 'event-type', + 'event-nofinish', 'event-adjust', 'event-ignore', 'event-id']; // All fields in the item table const ITEM_FIELDLIST = ['id', 'uid', 'parent', 'uri', 'parent-uri', 'thr-parent', 'guid', 'uri-id', 'parent-uri-id', 'thr-parent-id', 'vid', - 'contact-id', 'type', 'wall', 'gravity', 'extid', 'psid', + 'contact-id', 'wall', 'gravity', 'extid', 'psid', 'created', 'edited', 'commented', 'received', 'changed', 'verb', 'postopts', 'plink', 'resource-id', 'event-id', 'inform', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type', - 'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark', + 'private', 'pubmail', 'visible', 'starred', 'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global', 'network', 'title', 'content-warning', 'body', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object-type', 'object', 'target-type', 'target', 'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network', 'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'causer-id']; - // Item fiels that still are in use + // Item fields that still are in use const USED_FIELDLIST = ['id', 'parent', 'guid', 'uri', 'uri-id', 'parent-uri', 'parent-uri-id', 'thr-parent', 'thr-parent-id', 'created', 'edited', 'commented', 'received', 'changed', 'gravity', 'network', 'owner-id', 'author-id', 'causer-id', 'vid', 'extid', 'post-type', - 'global', 'private', 'visible', 'moderated', 'deleted', 'uid', 'contact-id', + 'global', 'private', 'visible', 'deleted', 'uid', 'contact-id', 'wall', 'origin', 'pubmail', 'starred', 'unseen', 'mention', 'forum_mode', 'psid', - 'event-id', 'type', 'bookmark']; + 'event-id']; // Legacy item fields that aren't stored any more in the item table const LEGACY_FIELDLIST = ['uri-hash', 'iaid', 'icid', 'attach', @@ -980,6 +984,12 @@ class Item Post\Media::insertFromAttachment($item['uri-id'], $item['attach']); } + if (empty($item['event-id'])) { + unset($item['event-id']); + } + + Post::insert($item['uri-id'], $item); + if ($item['gravity'] == GRAVITY_PARENT) { Post\Thread::insert($item['uri-id'], $item); } @@ -1010,6 +1020,12 @@ class Item Tag::storeFromBody($item['uri-id'], $item['body']); } + $condition = ['uri-id' => $item['uri-id'], 'uid' => $item['uid']]; + if (Post::exists($condition)) { + Logger::notice('Item is already inserted - aborting', $condition); + return 0; + } + $id = Post\User::insert($item['uri-id'], $item['uid'], $item); if (!$id) { Logger::notice('Post-User is already inserted - aborting', ['uid' => $item['uid'], 'uri-id' => $item['uri-id']]); @@ -1021,12 +1037,6 @@ class Item Post\ThreadUser::insert($item['uri-id'], $item['uid'], $item); } - $condition = ['uri-id' => $item['uri-id'], 'uid' => $item['uid'], 'network' => $item['network']]; - if (Post::exists($condition)) { - Logger::notice('Item is already inserted - aborting', $condition); - return 0; - } - // Remove all fields that aren't part of the item table $table_fields = DBStructure::getFieldsForTable('item', $item); @@ -1226,7 +1236,7 @@ class Item // Only distribute public items from native networks $condition = ['id' => $itemid, 'uid' => 0, 'network' => array_merge(Protocol::FEDERATED ,['']), - 'visible' => true, 'deleted' => false, 'moderated' => false, 'private' => [self::PUBLIC, self::UNLISTED]]; + 'visible' => true, 'deleted' => false, 'private' => [self::PUBLIC, self::UNLISTED]]; $item = Post::selectFirst(self::ITEM_FIELDLIST, $condition); if (!DBA::isResult($item)) { return; @@ -1405,7 +1415,7 @@ class Item */ private static function addShadow($itemid) { - $fields = ['uid', 'private', 'moderated', 'visible', 'deleted', 'network', 'uri-id']; + $fields = ['uid', 'private', 'visible', 'deleted', 'network', 'uri-id']; $condition = ['id' => $itemid, 'parent' => [0, $itemid]]; $item = Post::selectFirst($fields, $condition); @@ -1419,7 +1429,7 @@ class Item } // Is it a visible public post? - if (!$item["visible"] || $item["deleted"] || $item["moderated"] || ($item["private"] == self::PRIVATE)) { + if (!$item["visible"] || $item["deleted"] || ($item["private"] == self::PRIVATE)) { return; } @@ -2154,7 +2164,7 @@ class Item $condition[0] .= " AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY"; $condition[] = $days; - $items = Post::select(['resource-id', 'starred', 'type', 'id', 'post-type', 'uid', 'uri-id'], $condition); + $items = Post::select(['resource-id', 'starred', 'id', 'post-type', 'uid', 'uri-id'], $condition); if (!DBA::isResult($items)) { return; @@ -2187,9 +2197,9 @@ class Item continue; } elseif (!$expire_starred && intval($item['starred'])) { continue; - } elseif (!$expire_notes && (($item['type'] == 'note') || ($item['post-type'] == self::PT_PERSONAL_NOTE))) { + } elseif (!$expire_notes && ($item['post-type'] == self::PT_PERSONAL_NOTE)) { continue; - } elseif (!$expire_items && ($item['type'] != 'note') && ($item['post-type'] != self::PT_PERSONAL_NOTE)) { + } elseif (!$expire_items && ($item['post-type'] != self::PT_PERSONAL_NOTE)) { continue; } @@ -2203,7 +2213,7 @@ class Item public static function firstPostDate($uid, $wall = false) { - $condition = ['gravity' => GRAVITY_PARENT, 'uid' => $uid, 'wall' => $wall, 'deleted' => false, 'visible' => true, 'moderated' => false]; + $condition = ['gravity' => GRAVITY_PARENT, 'uid' => $uid, 'wall' => $wall, 'deleted' => false, 'visible' => true]; $params = ['order' => ['received' => false]]; $thread = Post::selectFirst(['received'], $condition, $params); if (DBA::isResult($thread)) { diff --git a/src/Model/Post.php b/src/Model/Post.php index a3d537b3d..30515d711 100644 --- a/src/Model/Post.php +++ b/src/Model/Post.php @@ -21,13 +21,42 @@ namespace Friendica\Model; +use BadMethodCallException; use Friendica\Core\Logger; +use Friendica\Core\System; +use Friendica\Database\Database; use Friendica\Database\DBA; use Friendica\Database\DBStructure; use Friendica\Protocol\Activity; class Post { + /** + * Insert a new post entry + * + * @param integer $uri_id + * @param array $fields + * @return int ID of inserted post + * @throws \Exception + */ + public static function insert(int $uri_id, array $data = []) + { + if (empty($uri_id)) { + throw new BadMethodCallException('Empty URI_id'); + } + + $fields = DBStructure::getFieldsForTable('post', $data); + + // Additionally assign the key fields + $fields['uri-id'] = $uri_id; + + if (!DBA::insert('post', $fields, Database::INSERT_IGNORE)) { + return 0; + } + + return DBA::lastInsertId(); + } + /** * Fetch a single post row * @@ -189,12 +218,9 @@ class Post private static function selectView(string $view, array $selected = [], array $condition = [], $params = []) { if (empty($selected)) { - $selected = array_merge(['author-addr', 'author-nick', 'owner-addr', 'owner-nick', 'causer-addr', 'causer-nick', - 'causer-network', 'photo', 'name-date', 'uri-date', 'avatar-date', 'thumb', 'dfrn-id', - 'parent-guid', 'parent-network', 'parent-author-id', 'parent-author-link', 'parent-author-name', - 'parent-author-network', 'signed_text', 'language', 'raw-body'], Item::DISPLAY_FIELDLIST, Item::ITEM_FIELDLIST); - - if ($view != 'post-view') { + $selected = array_merge(Item::DISPLAY_FIELDLIST, Item::ITEM_FIELDLIST); + + if ($view == 'post-thread-view') { $selected = array_merge($selected, ['ignored', 'iid']); } } @@ -216,7 +242,13 @@ class Post */ public static function select(array $selected = [], array $condition = [], $params = []) { - return self::selectView('post-view', $selected, $condition, $params); + $timestamp = microtime(true); + $data = self::selectView('post-view', $selected, $condition, $params); + + $duration = microtime(true) - $timestamp;; + if ($duration > 0.1) + Logger::info('Blubb', ['duration' => $duration, 'selected' => $selected, 'condition' => $condition, 'params' => $params, 'callstack' => System::callstack(20)]); + return $data; } /** @@ -253,7 +285,7 @@ class Post } $condition = DBA::mergeConditions($condition, - ["`visible` AND NOT `deleted` AND NOT `moderated` + ["`visible` AND NOT `deleted` AND NOT `author-blocked` AND NOT `owner-blocked` AND (NOT `causer-blocked` OR `causer-id` = ?) AND NOT `contact-blocked` AND ((NOT `contact-readonly` AND NOT `contact-pending` AND (`contact-rel` IN (?, ?))) @@ -299,6 +331,7 @@ class Post */ public static function selectForUser($uid, array $selected = [], array $condition = [], $params = []) { + //Logger::info('Blubb', ['uid' => $uid, 'selected' => $selected, 'condition' => $condition, 'params' => $params]); return self::selectViewForUser('post-view', $uid, $selected, $condition, $params); } @@ -434,6 +467,20 @@ class Post $affected = max($affected, DBA::affectedRows()); } + $update_fields = DBStructure::getFieldsForTable('post', $fields); + if (!empty($update_fields)) { + if (empty($uriids)) { + $rows = DBA::selectToArray('post-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]); + $uriids = array_column($rows, 'uri-id'); + } + if (!DBA::update('post', $update_fields, ['uri-id' => $uriids])) { + DBA::rollback(); + Logger::notice('Updating post failed', ['fields' => $update_fields, 'condition' => $condition]); + return false; + } + $affected = max($affected, DBA::affectedRows()); + } + $update_fields = Post\DeliveryData::extractFields($fields); if (!empty($update_fields)) { if (empty($uriids)) { @@ -450,7 +497,7 @@ class Post $update_fields = DBStructure::getFieldsForTable('post-thread', $fields); if (!empty($update_fields)) { - $rows = DBA::selectToArray('post-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]); + $rows = DBA::selectToArray('post-view', ['uri-id'], $thread_condition, ['group_by' => ['uri-id']]); $uriids = array_column($rows, 'uri-id'); if (!DBA::update('post-thread', $update_fields, ['uri-id' => $uriids])) { DBA::rollback(); @@ -494,4 +541,20 @@ class Post Logger::info('Updated posts', ['rows' => $affected]); return $affected; } + + /** + * Delete a row from the post table + * + * @param array $conditions Field condition(s) + * @param array $options + * - cascade: If true we delete records in other tables that depend on the one we're deleting through + * relations (default: true) + * + * @return boolean was the delete successful? + * @throws \Exception + */ + public static function delete(array $conditions, array $options = []) + { + return DBA::delete('post', $conditions, $options); + } } diff --git a/src/Module/Conversation/Network.php b/src/Module/Conversation/Network.php index f3a60b48f..be87da5f6 100644 --- a/src/Module/Conversation/Network.php +++ b/src/Module/Conversation/Network.php @@ -434,7 +434,7 @@ class Network extends BaseModule } if (DBA::isResult($items)) { - $parents = array_column($items, 'parent'); + $parents = array_column($items, 'parent-uri-id'); } else { $parents = []; } @@ -446,7 +446,7 @@ class Network extends BaseModule $condition = ['unseen' => true, 'uid' => local_user()]; self::setItemsSeenByCondition($condition); } elseif (!empty($parents)) { - $condition = ['unseen' => true, 'uid' => local_user(), 'parent' => $parents]; + $condition = ['unseen' => true, 'uid' => local_user(), 'parent-uri-id' => $parents]; self::setItemsSeenByCondition($condition); } diff --git a/src/Module/Profile/Status.php b/src/Module/Profile/Status.php index 7684c8435..267e3c189 100644 --- a/src/Module/Profile/Status.php +++ b/src/Module/Profile/Status.php @@ -189,7 +189,7 @@ class Status extends BaseProfile 0, $a->profile['uid']]); $condition = DBA::mergeConditions($condition, ['uid' => $a->profile['uid'], 'network' => Protocol::FEDERATED, - 'visible' => true, 'deleted' => false, 'moderated' => false]); + 'visible' => true, 'deleted' => false]); $pager = new Pager(DI::l10n(), $args->getQueryString(), $itemspage_network); $params = ['limit' => [$pager->getStart(), $pager->getItemsPerPage()], 'order' => ['received' => true]]; diff --git a/src/Module/Search/Filed.php b/src/Module/Search/Filed.php index 670554276..f14c29aa3 100644 --- a/src/Module/Search/Filed.php +++ b/src/Module/Search/Filed.php @@ -9,6 +9,7 @@ use Friendica\Content\Widget; use Friendica\Core\Renderer; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Model\Item; use Friendica\Model\Post; use Friendica\Model\Post\Category; use Friendica\Module\BaseSearch; @@ -69,7 +70,7 @@ class Filed extends BaseSearch $item_condition = ['uid' => local_user(), 'uri-id' => $posts]; $item_params = ['order' => ['uri-id' => true]]; - $items = Post::toArray(Post::selectForUser(local_user(), [], $item_condition, $item_params)); + $items = Post::toArray(Post::selectForUser(local_user(), Item::DISPLAY_FIELDLIST, $item_condition, $item_params)); $o .= conversation(DI::app(), $items, 'filed', false, false, '', local_user()); diff --git a/src/Module/Search/Index.php b/src/Module/Search/Index.php index 78f200810..e0050f405 100644 --- a/src/Module/Search/Index.php +++ b/src/Module/Search/Index.php @@ -172,7 +172,7 @@ class Index extends BaseSearch if (!empty($uriids)) { $params = ['order' => ['id' => true], 'group_by' => ['uri-id']]; - $items = Post::toArray(Post::selectForUser(local_user(), [], ['uri-id' => $uriids], $params)); + $items = Post::toArray(Post::selectForUser(local_user(), Item::DISPLAY_FIELDLIST, ['uri-id' => $uriids], $params)); } if (empty($items)) { diff --git a/src/Module/Update/Profile.php b/src/Module/Update/Profile.php index f660d96be..93a3752a4 100644 --- a/src/Module/Update/Profile.php +++ b/src/Module/Update/Profile.php @@ -81,7 +81,7 @@ class Profile extends BaseModule "SELECT DISTINCT(`parent-uri-id`) AS `uri-id`, `created` FROM `post-view` WHERE `uid` = ? AND NOT `contact-blocked` AND NOT `contact-pending` AND `visible` AND (NOT `deleted` OR `gravity` = ?) - AND NOT `moderated` AND `wall` $sql_extra4 $sql_extra + AND `wall` $sql_extra4 $sql_extra ORDER BY `received` DESC", $a->profile['uid'], GRAVITY_ACTIVITY diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index f281c7ee6..ba2b9e734 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -868,8 +868,9 @@ class Processor } $replyto = JsonLD::fetchElement($activity['as:object'], 'as:inReplyTo', '@id'); - if (Post::exists(['uri' => $replyto])) { - Logger::info('Post is a reply to an existing post - accepted', ['id' => $id, 'replyto' => $replyto]); + $uriid = ItemURI::getIdByURI($replyto); + if (Post::exists(['uri-id' => $uriid])) { + Logger::info('Post is a reply to an existing post - accepted', ['id' => $id, 'uri-id' => $uriid, 'replyto' => $replyto]); return true; } diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php index f48135f77..eef82f153 100644 --- a/src/Protocol/ActivityPub/Receiver.php +++ b/src/Protocol/ActivityPub/Receiver.php @@ -930,7 +930,7 @@ class Receiver } else { Logger::log('Empty content for ' . $object_id . ', check if content is available locally.', Logger::DEBUG); - $item = Post::selectFirst([], ['uri' => $object_id]); + $item = Post::selectFirst(Item::DELIVER_FIELDLIST, ['uri' => $object_id]); if (!DBA::isResult($item)) { Logger::log('Object with url ' . $object_id . ' was not found locally.', Logger::DEBUG); return false; diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 401d05c56..62bdb7c4a 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -258,7 +258,7 @@ class Transmitter $condition = array_merge($condition, ['author-id' => $public_contact, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], - 'deleted' => false, 'visible' => true, 'moderated' => false]); + 'deleted' => false, 'visible' => true]); $count = Post::count($condition); @@ -1045,19 +1045,19 @@ class Transmitter public static function createActivityFromItem(int $item_id, bool $object_mode = false) { Logger::info('Fetching activity', ['item' => $item_id]); - $item = Post::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]); + $item = Post::selectFirst(Item::DELIVER_FIELDLIST, ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]); if (!DBA::isResult($item)) { return false; } // In case of a forum post ensure to return the original post if author and forum are on the same machine - if (!empty($item['forum_mode'])) { + if (($item['gravity'] == GRAVITY_PARENT) && !empty($item['forum_mode'])) { $author = Contact::getById($item['author-id'], ['nurl']); if (!empty($author['nurl'])) { $self = Contact::selectFirst(['uid'], ['nurl' => $author['nurl'], 'self' => true]); if (!empty($self['uid'])) { - $forum_item = Post::selectFirst([], ['uri-id' => $item['uri-id'], 'uid' => $self['uid']]); - if (DBA::isResult($item)) { + $forum_item = Post::selectFirst(Item::DELIVER_FIELDLIST, ['uri-id' => $item['uri-id'], 'uid' => $self['uid']]); + if (DBA::isResult($forum_item)) { $item = $forum_item; } } @@ -1645,7 +1645,7 @@ class Transmitter return []; } - $reshared_item = Post::selectFirst([], ['guid' => $reshared['guid']]); + $reshared_item = Post::selectFirst(Item::DELIVER_FIELDLIST, ['guid' => $reshared['guid']]); if (!DBA::isResult($reshared_item)) { return []; } diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index 027efb2d4..196d7c04f 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -887,9 +887,9 @@ class Feed $params = ['order' => ['received' => true], 'limit' => $max_items]; if ($filter === 'posts') { - $ret = Post::selectThread([], $condition, $params); + $ret = Post::selectThread(Item::DELIVER_FIELDLIST, $condition, $params); } else { - $ret = Post::select([], $condition, $params); + $ret = Post::select(Item::DELIVER_FIELDLIST, $condition, $params); } $items = Post::toArray($ret); @@ -1041,7 +1041,7 @@ class Feed $condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => [Item::PUBLIC, Item::UNLISTED], 'network' => Protocol::FEDERATED]; - $repeated_item = Post::selectFirst([], $condition); + $repeated_item = Post::selectFirst(Item::DELIVER_FIELDLIST, $condition); if (!DBA::isResult($repeated_item)) { return false; } diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index 3c6b8775b..d5a3e8f5c 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -35,6 +35,7 @@ use Friendica\Util\Network; use Friendica\Core\Worker; use Friendica\Model\Conversation; use Friendica\Model\FContact; +use Friendica\Model\Item; use Friendica\Protocol\Relay; class Delivery @@ -80,9 +81,9 @@ class Delivery } $parent_id = intval($item['parent']); - $condition = ['id' => [$target_id, $parent_id], 'visible' => true, 'moderated' => false]; + $condition = ['id' => [$target_id, $parent_id], 'visible' => true]; $params = ['order' => ['id']]; - $itemdata = Model\Post::select([], $condition, $params); + $itemdata = Model\Post::select(Item::DELIVER_FIELDLIST, $condition, $params); while ($item = Model\Post::fetch($itemdata)) { if ($item['verb'] == Activity::ANNOUNCE) { diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 4044e3769..312dcc0f9 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -100,8 +100,8 @@ class Notifier $delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'addr', 'network', 'protocol', 'batch'], $condition); } else { // find ancestors - $condition = ['id' => $target_id, 'visible' => true, 'moderated' => false]; - $target_item = Post::selectFirst([], $condition); + $condition = ['id' => $target_id, 'visible' => true]; + $target_item = Post::selectFirst(Item::DELIVER_FIELDLIST, $condition); if (!DBA::isResult($target_item) || !intval($target_item['parent'])) { Logger::info('No target item', ['cmd' => $cmd, 'target' => $target_id]); @@ -117,9 +117,9 @@ class Notifier return; } - $condition = ['parent' => $target_item['parent'], 'visible' => true, 'moderated' => false]; + $condition = ['parent' => $target_item['parent'], 'visible' => true]; $params = ['order' => ['id']]; - $items_stmt = Post::select([], $condition, $params); + $items_stmt = Post::select(Item::DELIVER_FIELDLIST, $condition, $params); if (!DBA::isResult($items_stmt)) { Logger::info('No item found', ['cmd' => $cmd, 'target' => $target_id]); return; @@ -792,6 +792,6 @@ class Notifier */ public static function isForumPost(array $item) { - return !empty($item['forum_mode']); + return ($item['gravity'] == GRAVITY_PARENT) && !empty($item['forum_mode']); } } diff --git a/src/Worker/RemoveContact.php b/src/Worker/RemoveContact.php index e1e6cbcf9..6d48dd956 100644 --- a/src/Worker/RemoveContact.php +++ b/src/Worker/RemoveContact.php @@ -47,13 +47,14 @@ class RemoveContact { $condition = ['uid' => $contact['uid'], 'contact-id' => $id]; } do { - $items = Post::select(['id', 'guid', 'uri-id', 'uid'], $condition, ['limit' => 100]); + $items = Post::select(['id', 'post-user-id', 'uri-id', 'guid'], $condition, ['limit' => 100]); while ($item = Post::fetch($items)) { - Logger::info('Delete removed contact item', ['id' => $item['id'], 'guid' => $item['guid']]); + Logger::info('Delete removed contact item', ['id' => $item['id'], 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]); DBA::delete('item', ['id' => $item['id']]); - Post\User::delete(['uri-id' => $item['uri-id'], 'uid' => $item['uid']]); + Post::delete(['uri-id' => $item['uri-id']]); + Post\ThreadUser::delete(['post-user-id' => $item['post-user-id']]); Post\Thread::delete(['uri-id' => $item['uri-id']]); - Post\ThreadUser::delete(['uri-id' => $item['uri-id'], 'uid' => $item['uid']]); + Post\User::delete(['id' => $item['post-user-id']]); } DBA::close($items); } while (Post::exists($condition)); diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 3002f6ac4..b91cd8a93 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -55,7 +55,7 @@ use Friendica\Database\DBA; if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1399); + define('DB_UPDATE_VERSION', 1400); } return [ @@ -771,7 +771,6 @@ return [ "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" => ""], - "moderated" => ["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"], @@ -787,10 +786,11 @@ return [ // 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 - "type" => ["type" => "varchar(20)", "comment" => ""], - "bookmark" => ["type" => "boolean", "comment" => ""], "mention" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "The owner of this item was mentioned in it"], - // Deprecated fields. Will be removed in upcoming versions + // 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"], @@ -1086,6 +1086,38 @@ return [ "resource-id" => ["resource-id"], ] ], + "post" => [ + "comment" => "Structure for all posts", + "fields" => [ + "uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"], + "parent-uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table that contains the 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)"], + "received" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "datetime"], + "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"], + "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"], + "vid" => ["type" => "smallint unsigned", "foreign" => ["verb" => "id", "on delete" => "restrict"], "comment" => "Id of the verb table entry that contains the activity verbs"], + "private" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "0=public, 1=private, 2=unlisted"], + "global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], + "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], + "deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been marked for deletion"] + ], + "indexes" => [ + "PRIMARY" => ["uri-id"], + "parent-uri-id" => ["parent-uri-id"], + "thr-parent-id" => ["thr-parent-id"], + "owner-id" => ["owner-id"], + "author-id" => ["author-id"], + "causer-id" => ["causer-id"], + "vid" => ["vid"], + "received" => ["received"], + ] + ], "post-category" => [ "comment" => "post relation to categories", "fields" => [ @@ -1209,12 +1241,30 @@ return [ "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"], "uri-id" => ["type" => "int unsigned", "not null" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"], + "parent-uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table that contains the 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)"], + "received" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "datetime"], + "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"], + "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"], + "vid" => ["type" => "smallint unsigned", "foreign" => ["verb" => "id", "on delete" => "restrict"], "comment" => "Id of the verb table entry that contains the activity verbs"], + "private" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "0=public, 1=private, 2=unlisted"], + "global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], + "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], + "deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been marked for deletion"], "uid" => ["type" => "mediumint unsigned", "not null" => "1", "foreign" => ["user" => "uid"], "comment" => "Owner id which owns this copy of the item"], "protocol" => ["type" => "tinyint unsigned", "comment" => "Protocol used to deliver the item for this user"], "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id"], "comment" => "contact.id"], + "event-id" => ["type" => "int unsigned", "foreign" => ["event" => "id"], "comment" => "Used to link to the event.id"], "unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "post has not been seen"], "hidden" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Marker to hide the post from the user"], "notification-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""], + "wall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "This item was posted to the wall of uid"], "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"], ], @@ -1225,12 +1275,36 @@ return [ "contact-id" => ["contact-id"], "psid" => ["psid"], "uid_hidden" => ["uid", "hidden"], + "event-id" => ["event-id"], + "uid_wall" => ["uid", "wall"], + "parent-uri-id" => ["parent-uri-id"], + "thr-parent-id" => ["thr-parent-id"], + "owner-id" => ["owner-id"], + "author-id" => ["author-id"], + "causer-id" => ["causer-id"], + "vid" => ["vid"], + "uid_received" => ["uid", "received"], + "uid_unseen_contactid" => ["uid", "unseen", "contact-id"], + "uid_network_received" => ["uid", "network", "received"], + "uid_contactid_received" => ["uid", "contact-id", "received"], + "authorid_received" => ["author-id", "received"], + "uid_unseen_wall" => ["uid", "unseen", "wall"], + "uid_eventid" => ["uid", "event-id"], + "psid_wall" => ["psid", "wall"], ], ], "post-thread-user" => [ "comment" => "Thread related data per user", "fields" => [ "uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"], + "owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Item owner"], + "author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Item author"], + "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"], + "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""], + "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""], + "received" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""], + "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"], + "commented" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""], "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "primary" => "1", "foreign" => ["user" => "uid"], "comment" => "Owner id which owns this copy of the item"], "pinned" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "The thread is pinned on the profile page"], "starred" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], @@ -1254,6 +1328,24 @@ return [ "contact-id" => ["contact-id"], "psid" => ["psid"], "post-user-id" => ["post-user-id"], + "owner-id" => ["owner-id"], + "causer-id" => ["causer-id"], + "uid_received" => ["uid", "received"], + "uid_commented" => ["uid", "commented"], + "uid_changed" => ["uid", "changed"], + "uid_contact-id" => ["uid", "contact-id", "received"], + "uid_unseen_contactid" => ["uid", "unseen", "contact-id"], + "uid_network_received" => ["uid", "network", "received"], + "uid_network_commented" => ["uid", "network", "commented"], + "uid_contact-id_received" => ["uid", "contact-id", "received"], + "author-id_received" => ["author-id", "received"], + "uid_wall_changed" => ["uid", "wall", "changed"], + "uid_unseen_wall" => ["uid", "unseen", "wall"], + "mention_uid" => ["mention", "uid"], + "psid_wall" => ["psid", "wall"], + "received" => ["received"], + "commented" => ["commented"], + "changed" => ["changed"], ] ], "post-user-notification" => [ diff --git a/static/dbview.config.php b/static/dbview.config.php index 6b48a9532..cd1e81d32 100644 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -42,41 +42,38 @@ "id" => ["item", "id"], "item_id" => ["item", "id"], "post-user-id" => ["post-user", "id"], - "uid" => ["item", "uid"], + "uid" => ["post-user", "uid"], "parent" => ["item", "parent"], - "uri" => ["item", "uri"], - "uri-id" => ["item", "uri-id"], - "parent-uri" => ["item", "parent-uri"], - "parent-uri-id" => ["item", "parent-uri-id"], - "thr-parent" => ["item", "thr-parent"], - "thr-parent-id" => ["item", "thr-parent-id"], - "guid" => ["item", "guid"], - "type" => ["item", "type"], - "wall" => ["item", "wall"], - "gravity" => ["item", "gravity"], + "uri" => ["item-uri", "uri"], + "uri-id" => ["post-user", "uri-id"], + "parent-uri" => ["parent-item-uri", "uri"], + "parent-uri-id" => ["post-user", "parent-uri-id"], + "thr-parent" => ["thr-parent-item-uri", "uri"], + "thr-parent-id" => ["post-user", "thr-parent-id"], + "guid" => ["item-uri", "guid"], + "wall" => ["post-user", "wall"], + "gravity" => ["post-user", "gravity"], "extid" => ["item", "extid"], - "created" => ["item", "created"], - "edited" => ["item", "edited"], - "commented" => ["item", "commented"], - "received" => ["item", "received"], - "changed" => ["item", "changed"], - "post-type" => ["item", "post-type"], - "private" => ["item", "private"], - "pubmail" => ["item", "pubmail"], - "moderated" => ["item", "moderated"], - "visible" => ["item", "visible"], - "starred" => ["item", "starred"], - "bookmark" => ["item", "bookmark"], - "unseen" => ["item", "unseen"], - "deleted" => ["item", "deleted"], - "origin" => ["item", "origin"], - "forum_mode" => ["item", "forum_mode"], - "mention" => ["item", "mention"], - "global" => ["item", "global"], - "network" => ["item", "network"], - "vid" => ["item", "vid"], - "psid" => ["item", "psid"], - "verb" => "IF (`item`.`vid` IS NULL, '', `verb`.`name`)", + "created" => ["post-user", "created"], + "edited" => ["post-user", "edited"], + "commented" => ["post-thread-user", "commented"], + "received" => ["post-user", "received"], + "changed" => ["post-thread-user", "changed"], + "post-type" => ["post-user", "post-type"], + "private" => ["post-user", "private"], + "pubmail" => ["post-thread-user", "pubmail"], + "visible" => ["post-user", "visible"], + "starred" => ["post-thread-user", "starred"], + "unseen" => ["post-user", "unseen"], + "deleted" => ["post-user", "deleted"], + "origin" => ["post-user", "origin"], + "forum_mode" => ["post-thread-user", "forum_mode"], + "mention" => ["post-thread-user", "mention"], + "global" => ["post-user", "global"], + "network" => ["post-user", "network"], + "vid" => ["post-user", "vid"], + "psid" => ["post-user", "psid"], + "verb" => "IF (`post-user`.`vid` IS NULL, '', `verb`.`name`)", "title" => ["post-content", "title"], "content-warning" => ["post-content", "content-warning"], "raw-body" => ["post-content", "raw-body"], @@ -93,7 +90,7 @@ "target-type" => ["post-content", "target-type"], "target" => ["post-content", "target"], "resource-id" => ["post-content", "resource-id"], - "contact-id" => ["item", "contact-id"], + "contact-id" => ["post-user", "contact-id"], "contact-link" => ["contact", "url"], "contact-addr" => ["contact", "addr"], "contact-name" => ["contact", "name"], @@ -108,7 +105,7 @@ "contact-rel" => ["contact", "rel"], "contact-uid" => ["contact", "uid"], "contact-contact-type" => ["contact", "contact-type"], - "writable" => "IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`)", + "writable" => "IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`)", "self" => ["contact", "self"], "cid" => ["contact", "id"], "alias" => ["contact", "alias"], @@ -118,7 +115,7 @@ "avatar-date" => ["contact", "avatar-date"], "thumb" => ["contact", "thumb"], "dfrn-id" => ["contact", "dfrn-id"], - "author-id" => ["item", "author-id"], + "author-id" => ["post-user", "author-id"], "author-link" => ["author", "url"], "author-addr" => ["author", "addr"], "author-name" => "IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`)", @@ -127,7 +124,7 @@ "author-network" => ["author", "network"], "author-blocked" => ["author", "blocked"], "author-hidden" => ["author", "hidden"], - "owner-id" => ["item", "owner-id"], + "owner-id" => ["post-user", "owner-id"], "owner-link" => ["owner", "url"], "owner-addr" => ["owner", "addr"], "owner-name" => "IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`)", @@ -136,7 +133,7 @@ "owner-network" => ["owner", "network"], "owner-blocked" => ["owner", "blocked"], "owner-hidden" => ["owner", "hidden"], - "causer-id" => ["item", "causer-id"], + "causer-id" => ["post-user", "causer-id"], "causer-link" => ["causer", "url"], "causer-addr" => ["causer", "addr"], "causer-name" => ["causer", "name"], @@ -151,11 +148,11 @@ "delivery_queue_count" => ["post-delivery-data", "queue_count"], "delivery_queue_done" => ["post-delivery-data", "queue_done"], "delivery_queue_failed" => ["post-delivery-data", "queue_failed"], - "allow_cid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`allow_cid`)", - "allow_gid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`allow_gid`)", - "deny_cid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`deny_cid`)", - "deny_gid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`deny_gid`)", - "event-id" => ["item", "event-id"], + "allow_cid" => "IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`)", + "allow_gid" => "IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`)", + "deny_cid" => "IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`)", + "deny_gid" => "IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`)", + "event-id" => ["post-user", "event-id"], "event-created" => ["event", "created"], "event-edited" => ["event", "edited"], "event-start" => ["event", "start"], @@ -168,27 +165,31 @@ "event-adjust" => ["event", "adjust"], "event-ignore" => ["event", "ignore"], "signed_text" => ["diaspora-interaction", "interaction"], - "parent-guid" => ["parent-item", "guid"], - "parent-network" => ["parent-item", "network"], - "parent-author-id" => ["parent-item", "author-id"], - "parent-author-link" => ["parent-item-author", "url"], - "parent-author-name" => ["parent-item-author", "name"], - "parent-author-network" => ["parent-item-author", "network"], + "parent-guid" => ["parent-item-uri", "guid"], + "parent-network" => ["parent-post", "network"], + "parent-author-id" => ["parent-post", "author-id"], + "parent-author-link" => ["parent-post-author", "url"], + "parent-author-name" => ["parent-post-author", "name"], + "parent-author-network" => ["parent-post-author", "network"], ], - "query" => "FROM `item` - LEFT JOIN `post-user` ON `post-user`.`uri-id` = `item`.`uri-id` AND `post-user`.`uid` = `item`.`uid` - STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `item`.`author-id` - STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `item`.`owner-id` - STRAIGHT_JOIN `contact` AS `causer` ON `causer`.`id` = `item`.`causer-id` - LEFT JOIN `verb` ON `verb`.`id` = `item`.`vid` - LEFT JOIN `event` ON `event`.`id` = `item`.`event-id` - LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `item`.`uri-id` - LEFT JOIN `post-content` ON `post-content`.`uri-id` = `item`.`uri-id` - LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `item`.`uri-id` AND `item`.`origin` - LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid` - STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`uri-id` = `item`.`parent-uri-id` AND `parent-item`.`uid` = `item`.`uid` - STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id`" + "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` + INNER 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` + 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`" ], "post-thread-view" => [ "fields" => [ @@ -197,40 +198,37 @@ "item_id" => ["item", "id"], "uid" => ["post-thread-user", "uid"], "parent" => ["item", "parent"], - "uri" => ["item", "uri"], - "uri-id" => ["post-thread", "uri-id"], - "parent-uri" => ["item", "parent-uri"], - "parent-uri-id" => ["item", "parent-uri-id"], - "thr-parent" => ["item", "thr-parent"], - "thr-parent-id" => ["item", "thr-parent-id"], - "guid" => ["item", "guid"], - "type" => ["item", "type"], + "uri" => ["item-uri", "uri"], + "uri-id" => ["post-thread-user", "uri-id"], + "parent-uri" => ["parent-item-uri", "uri"], + "parent-uri-id" => ["post-user", "parent-uri-id"], + "thr-parent" => ["thr-parent-item-uri", "uri"], + "thr-parent-id" => ["post-user", "thr-parent-id"], + "guid" => ["item-uri", "guid"], "wall" => ["post-thread-user", "wall"], - "gravity" => ["item", "gravity"], + "gravity" => ["post-user", "gravity"], "extid" => ["item", "extid"], - "created" => ["post-thread", "created"], - "edited" => ["item", "edited"], - "commented" => ["post-thread", "commented"], - "received" => ["post-thread", "received"], - "changed" => ["post-thread", "changed"], - "post-type" => ["item", "post-type"], - "private" => ["item", "private"], + "created" => ["post-thread-user", "created"], + "edited" => ["post-user", "edited"], + "commented" => ["post-thread-user", "commented"], + "received" => ["post-thread-user", "received"], + "changed" => ["post-thread-user", "changed"], + "post-type" => ["post-user", "post-type"], + "private" => ["post-user", "private"], "pubmail" => ["post-thread-user", "pubmail"], - "moderated" => ["item", "moderated"], "ignored" => ["post-thread-user", "ignored"], - "visible" => ["item", "visible"], + "visible" => ["post-user", "visible"], "starred" => ["post-thread-user", "starred"], - "bookmark" => ["item", "bookmark"], "unseen" => ["post-thread-user", "unseen"], - "deleted" => ["item", "deleted"], + "deleted" => ["post-user", "deleted"], "origin" => ["post-thread-user", "origin"], "forum_mode" => ["post-thread-user", "forum_mode"], - "mention" => ["item", "mention"], - "global" => ["item", "global"], - "network" => ["post-thread", "network"], - "vid" => ["item", "vid"], + "mention" => ["post-thread-user", "mention"], + "global" => ["post-user", "global"], + "network" => ["post-thread-user", "network"], + "vid" => ["post-user", "vid"], "psid" => ["post-thread-user", "psid"], - "verb" => "IF (`item`.`vid` IS NULL, '', `verb`.`name`)", + "verb" => "IF (`post-user`.`vid` IS NULL, '', `verb`.`name`)", "title" => ["post-content", "title"], "content-warning" => ["post-content", "content-warning"], "raw-body" => ["post-content", "raw-body"], @@ -262,7 +260,7 @@ "contact-rel" => ["contact", "rel"], "contact-uid" => ["contact", "uid"], "contact-contact-type" => ["contact", "contact-type"], - "writable" => "IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`)", + "writable" => "IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`)", "self" => ["contact", "self"], "cid" => ["contact", "id"], "alias" => ["contact", "alias"], @@ -272,7 +270,7 @@ "avatar-date" => ["contact", "avatar-date"], "thumb" => ["contact", "thumb"], "dfrn-id" => ["contact", "dfrn-id"], - "author-id" => ["post-thread", "author-id"], + "author-id" => ["post-thread-user", "author-id"], "author-link" => ["author", "url"], "author-addr" => ["author", "addr"], "author-name" => "IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`)", @@ -281,7 +279,7 @@ "author-network" => ["author", "network"], "author-blocked" => ["author", "blocked"], "author-hidden" => ["author", "hidden"], - "owner-id" => ["post-thread", "owner-id"], + "owner-id" => ["post-thread-user", "owner-id"], "owner-link" => ["owner", "url"], "owner-addr" => ["owner", "addr"], "owner-name" => "IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`)", @@ -290,7 +288,7 @@ "owner-network" => ["owner", "network"], "owner-blocked" => ["owner", "blocked"], "owner-hidden" => ["owner", "hidden"], - "causer-id" => ["item", "causer-id"], + "causer-id" => ["post-thread-user", "causer-id"], "causer-link" => ["causer", "url"], "causer-addr" => ["causer", "addr"], "causer-name" => ["causer", "name"], @@ -309,7 +307,7 @@ "allow_gid" => "IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`)", "deny_cid" => "IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`)", "deny_gid" => "IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`)", - "event-id" => ["item", "event-id"], + "event-id" => ["post-user", "event-id"], "event-created" => ["event", "created"], "event-edited" => ["event", "edited"], "event-start" => ["event", "start"], @@ -322,28 +320,31 @@ "event-adjust" => ["event", "adjust"], "event-ignore" => ["event", "ignore"], "signed_text" => ["diaspora-interaction", "interaction"], - "parent-guid" => ["parent-item", "guid"], - "parent-network" => ["parent-item", "network"], - "parent-author-id" => ["parent-item", "author-id"], - "parent-author-link" => ["parent-item-author", "url"], - "parent-author-name" => ["parent-item-author", "name"], - "parent-author-network" => ["parent-item-author", "network"], + "parent-guid" => ["parent-item-uri", "guid"], + "parent-network" => ["parent-post", "network"], + "parent-author-id" => ["parent-post", "author-id"], + "parent-author-link" => ["parent-post-author", "url"], + "parent-author-name" => ["parent-post-author", "name"], + "parent-author-network" => ["parent-post-author", "network"], ], - "query" => "FROM `post-thread` - STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-thread`.`uri-id` - STRAIGHT_JOIN `item` ON `item`.`uri-id` = `post-thread`.`uri-id` AND `item`.`uid` = `post-thread-user`.`uid` - STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id` - STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread`.`author-id` - STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread`.`owner-id` - STRAIGHT_JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread`.`causer-id` - LEFT JOIN `verb` ON `verb`.`id` = `item`.`vid` - LEFT JOIN `event` ON `event`.`id` = `item`.`event-id` - LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread`.`uri-id` - LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread`.`uri-id` - LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-thread`.`uri-id` AND `post-thread-user`.`origin` + "query" => "FROM `post-thread-user` + INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id` + INNER 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` + 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 `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` - STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent` - STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id`" + 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`" ], "category-view" => [ "fields" => [ @@ -400,7 +401,7 @@ LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `parent-item`.`uid` AND `author`.`cid` = `parent-item`.`author-id` LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `parent-item`.`uid` AND `owner`.`cid` = `parent-item`.`owner-id` LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `parent-item`.`owner-id` - WHERE `parent-item`.`visible` AND NOT `parent-item`.`deleted` AND NOT `parent-item`.`moderated` + WHERE `parent-item`.`visible` AND NOT `parent-item`.`deleted` AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`) AND (`post-user`.`hidden` IS NULL OR NOT `post-user`.`hidden`) AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`) @@ -429,7 +430,7 @@ LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread`.`author-id` LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread`.`owner-id` LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread`.`owner-id` - WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` + WHERE `item`.`visible` AND NOT `item`.`deleted` AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`) AND (`post-thread-user`.`hidden` IS NULL OR NOT `post-thread-user`.`hidden`) AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`) diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index 175f2667a..4f85fe0ce 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -23,6 +23,7 @@ use Friendica\Core\Protocol; use Friendica\Model\Contact; use Friendica\Model\Item; use Friendica\Model\Notification; +use Friendica\Model\Verb; return [ // Empty these tables @@ -373,6 +374,86 @@ return [ 'post-user-id' => 12, ], ], + 'post' => [ + [ + 'uri-id' => 1, + 'parent-uri-id' => 1, + 'thr-parent-id' => 1, + 'gravity' => GRAVITY_PARENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 42, + 'causer-id' => 42, + 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'private' => Item::PUBLIC, + 'visible' => 1, + ], + [ + 'uri-id' => 2, + 'parent-uri-id' => 1, + 'thr-parent-id' => 1, + 'gravity' => GRAVITY_COMMENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 42, + 'causer-id' => 42, + 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'private' => Item::PUBLIC, + 'visible' => 1, + ], + [ + 'uri-id' => 3, + 'parent-uri-id' => 3, + 'thr-parent-id' => 3, + 'gravity' => GRAVITY_PARENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 43, + 'causer-id' => 43, + 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'private' => Item::PUBLIC, + 'visible' => 1, + ], + [ + 'uri-id' => 4, + 'parent-uri-id' => 1, + 'thr-parent-id' => 1, + 'gravity' => GRAVITY_COMMENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 44, + 'causer-id' => 44, + 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'private' => Item::PUBLIC, + 'visible' => 1, + ], + [ + 'uri-id' => 5, + 'parent-uri-id' => 1, + 'thr-parent-id' => 1, + 'gravity' => GRAVITY_COMMENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 42, + 'causer-id' => 42, + 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'private' => Item::PUBLIC, + 'visible' => 1, + ], + [ + 'uri-id' => 6, + 'parent-uri-id' => 6, + 'thr-parent-id' => 6, + 'gravity' => GRAVITY_PARENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 44, + 'causer-id' => 44, + 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'private' => Item::PUBLIC, + 'visible' => 1, + ], + ], 'item' => [ [ 'id' => 1, diff --git a/update.php b/update.php index 9b5c7ac6f..444189cc6 100644 --- a/update.php +++ b/update.php @@ -768,5 +768,53 @@ function update_1399() return Update::FAILED; } + return Update::SUCCESS; +} + +function update_1400() +{ +/* + if (!DBA::e("INSERT IGNORE INTO `post` (`uri-id`, `parent-uri-id`, `thr-parent-id`, `owner-id`, `author-id`, `network`, + `created`, `received`, `edited`, `gravity`, `causer-id`, `post-type`, `vid`, `private`, `visible`, `deleted`) + SELECT `uri-id`, `parent-uri-id`, `thr-parent-id`, `owner-id`, `author-id`, `network`, `created`, `received`, `edited`, + `gravity`, `causer-id`, `post-type`, `vid`, `private`, `visible`, `deleted` FROM `item`")) { + return Update::FAILED; + } + + if (!DBA::e("UPDATE `post` INNER JOIN `item` ON `item`.`uri-id` = `post`.`uri-id` AND `item`.`uid` = 0 + SET `post`.`global` = true")) { + return Update::FAILED; + +// -------------------------------------- + if (!DBA::e("UPDATE `post-user` INNER JOIN `item` ON `item`.`uri-id` = `post-user`.`uri-id` AND `item`.`uid` = `post-user`.`uid` + INNER JOIN `event` ON `item`.`event-id` = `event`.`id` AND `event`.`id` != 0 + SET `post-user`.`event-id` = `item`.`event-id`")) { + return Update::FAILED; + } + + if (!DBA::e("UPDATE `post-user` INNER JOIN `item` ON `item`.`uri-id` = `post-user`.`uri-id` AND `item`.`uid` = `post-user`.`uid` + SET `post-user`.`wall` = `item`.`wall`, `post-user`.`parent-uri-id` = `item`.`parent-uri-id`, + `post-user`.`thr-parent-id` = `item`.`thr-parent-id`, + `post-user`.`created` = `item`.`created`, `post-user`.`edited` = `item`.`edited`, + `post-user`.`received` = `item`.`received`, `post-user`.`gravity` = `item`.`gravity`, + `post-user`.`network` = `item`.`network`, `post-user`.`owner-id` = `item`.`owner-id`, + `post-user`.`author-id` = `item`.`author-id`, `post-user`.`causer-id` = `item`.`causer-id`, + `post-user`.`post-type` = `item`.`post-type`, `post-user`.`vid` = `item`.`vid`, + `post-user`.`private` = `item`.`private`, `post-user`.`global` = `item`.`global`, + `post-user`.`visible` = `item`.`visible`, `post-user`.`deleted` = `item`.`deleted`")) { + return Update::FAILED; + } + + */ + + if (!DBA::e("UPDATE `post-thread-user` INNER JOIN `post-thread` ON `post-thread-user`.`uri-id` = `post-thread`.`uri-id` + SET `post-thread-user`.`owner-id` = `post-thread`.`owner-id`, `post-thread-user`.`author-id` = `post-thread`.`author-id`, + `post-thread-user`.`causer-id` = `post-thread`.`causer-id`, `post-thread-user`.`network` = `post-thread`.`network`, + `post-thread-user`.`created` = `post-thread`.`created`, `post-thread-user`.`received` = `post-thread`.`received`, + `post-thread-user`.`changed` = `post-thread`.`changed`, `post-thread-user`.`commented` = `post-thread`.`commented`")) { + return Update::FAILED; + } + + return Update::SUCCESS; } From 07c07ec4992be06f695bb8e4443b5bd642d0098e Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 14 Feb 2021 09:43:27 +0000 Subject: [PATCH 02/25] More "item" traces removed --- database.sql | 494 ++++++++++++---------------- mod/item.php | 1 - src/Model/Item.php | 6 +- src/Model/Post.php | 8 +- src/Worker/CleanItemUri.php | 7 +- src/Worker/Cron.php | 3 - src/Worker/Expire.php | 9 +- src/Worker/ExpirePosts.php | 29 +- src/Worker/RemoveUnusedAvatars.php | 6 +- src/Worker/RemoveUnusedContacts.php | 28 +- src/Worker/RepairDatabase.php | 68 ---- src/Worker/UpdateContacts.php | 4 +- static/dbstructure.config.php | 4 + static/dbview.config.php | 117 ++++--- static/defaults.config.php | 4 - 15 files changed, 325 insertions(+), 463 deletions(-) delete mode 100644 src/Worker/RepairDatabase.php diff --git a/database.sql b/database.sql index 52a1d7eeb..69724c3e1 100644 --- a/database.sql +++ b/database.sql @@ -1033,6 +1033,7 @@ CREATE TABLE IF NOT EXISTS `post` ( `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri', `parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the parent uri', `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri', + `external-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the external 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)', `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime', @@ -1050,13 +1051,16 @@ CREATE TABLE IF NOT EXISTS `post` ( PRIMARY KEY(`uri-id`), INDEX `parent-uri-id` (`parent-uri-id`), INDEX `thr-parent-id` (`thr-parent-id`), + INDEX `external-id` (`external-id`), INDEX `owner-id` (`owner-id`), INDEX `author-id` (`author-id`), INDEX `causer-id` (`causer-id`), INDEX `vid` (`vid`), + INDEX `received` (`received`), 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 (`external-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, @@ -1194,6 +1198,23 @@ CREATE TABLE IF NOT EXISTS `post-thread` ( CREATE TABLE IF NOT EXISTS `post-user` ( `id` int unsigned NOT NULL auto_increment, `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri', + `parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the parent uri', + `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri', + `external-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the external 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)', + `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime', + `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', + `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)', + `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs', + `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted', + `global` boolean NOT NULL DEFAULT '0' COMMENT '', + `visible` boolean NOT NULL DEFAULT '0' COMMENT '', + `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been marked for deletion', `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item', `protocol` tinyint unsigned COMMENT 'Protocol used to deliver the item for this user', `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id', @@ -1212,7 +1233,29 @@ CREATE TABLE IF NOT EXISTS `post-user` ( INDEX `uid_hidden` (`uid`,`hidden`), INDEX `event-id` (`event-id`), INDEX `uid_wall` (`uid`,`wall`), + INDEX `parent-uri-id` (`parent-uri-id`), + INDEX `thr-parent-id` (`thr-parent-id`), + INDEX `external-id` (`external-id`), + INDEX `owner-id` (`owner-id`), + INDEX `author-id` (`author-id`), + INDEX `causer-id` (`causer-id`), + INDEX `vid` (`vid`), + INDEX `uid_received` (`uid`,`received`), + INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`), + INDEX `uid_network_received` (`uid`,`network`,`received`), + INDEX `uid_contactid_received` (`uid`,`contact-id`,`received`), + INDEX `authorid_received` (`author-id`,`received`), + INDEX `uid_unseen_wall` (`uid`,`unseen`,`wall`), + INDEX `uid_eventid` (`uid`,`event-id`), + INDEX `psid_wall` (`psid`,`wall`), 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 (`external-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 (`event-id`) REFERENCES `event` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE, @@ -1224,6 +1267,14 @@ CREATE TABLE IF NOT EXISTS `post-user` ( -- CREATE TABLE IF NOT EXISTS `post-thread-user` ( `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri', + `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner', + `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item author', + `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', + `network` char(4) NOT NULL DEFAULT '' COMMENT '', + `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '', + `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '', + `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', + `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '', `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id which owns this copy of the item', `pinned` boolean NOT NULL DEFAULT '0' COMMENT 'The thread is pinned on the profile page', `starred` boolean NOT NULL DEFAULT '0' COMMENT '', @@ -1245,7 +1296,28 @@ CREATE TABLE IF NOT EXISTS `post-thread-user` ( INDEX `contact-id` (`contact-id`), INDEX `psid` (`psid`), INDEX `post-user-id` (`post-user-id`), + INDEX `owner-id` (`owner-id`), + INDEX `causer-id` (`causer-id`), + INDEX `uid_received` (`uid`,`received`), + INDEX `uid_commented` (`uid`,`commented`), + INDEX `uid_changed` (`uid`,`changed`), + INDEX `uid_contact-id` (`uid`,`contact-id`,`received`), + INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`), + INDEX `uid_network_received` (`uid`,`network`,`received`), + INDEX `uid_network_commented` (`uid`,`network`,`commented`), + INDEX `uid_contact-id_received` (`uid`,`contact-id`,`received`), + INDEX `author-id_received` (`author-id`,`received`), + INDEX `uid_wall_changed` (`uid`,`wall`,`changed`), + INDEX `uid_unseen_wall` (`uid`,`unseen`,`wall`), + INDEX `mention_uid` (`mention`,`uid`), + INDEX `psid_wall` (`psid`,`wall`), + INDEX `received` (`received`), + INDEX `commented` (`commented`), + INDEX `changed` (`changed`), FOREIGN KEY (`uri-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 (`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, @@ -1517,192 +1589,42 @@ CREATE TABLE IF NOT EXISTS `workerqueue` ( DROP VIEW IF EXISTS `post-view`; CREATE VIEW `post-view` AS SELECT `item`.`id` AS `id`, - `item`.`id` AS `item_id`, - `post-user`.`id` AS `post-user-id`, - `item`.`uid` AS `uid`, - `item`.`parent` AS `parent`, - `item`.`uri` AS `uri`, - `item`.`uri-id` AS `uri-id`, - `item`.`parent-uri` AS `parent-uri`, - `item`.`parent-uri-id` AS `parent-uri-id`, - `item`.`thr-parent` AS `thr-parent`, - `item`.`thr-parent-id` AS `thr-parent-id`, - `item`.`guid` AS `guid`, - `item`.`wall` AS `wall`, - `item`.`gravity` AS `gravity`, - `item`.`extid` AS `extid`, - `item`.`created` AS `created`, - `item`.`edited` AS `edited`, - `item`.`commented` AS `commented`, - `item`.`received` AS `received`, - `item`.`changed` AS `changed`, - `item`.`post-type` AS `post-type`, - `item`.`private` AS `private`, - `item`.`pubmail` AS `pubmail`, - `item`.`visible` AS `visible`, - `item`.`starred` AS `starred`, - `item`.`unseen` AS `unseen`, - `item`.`deleted` AS `deleted`, - `item`.`origin` AS `origin`, - `item`.`forum_mode` AS `forum_mode`, - `item`.`mention` AS `mention`, - `item`.`global` AS `global`, - `item`.`network` AS `network`, - `item`.`vid` AS `vid`, - `item`.`psid` AS `psid`, - IF (`item`.`vid` IS NULL, '', `verb`.`name`) AS `verb`, - `post-content`.`title` AS `title`, - `post-content`.`content-warning` AS `content-warning`, - `post-content`.`raw-body` AS `raw-body`, - `post-content`.`body` AS `body`, - `post-content`.`rendered-hash` AS `rendered-hash`, - `post-content`.`rendered-html` AS `rendered-html`, - `post-content`.`language` AS `language`, - `post-content`.`plink` AS `plink`, - `post-content`.`location` AS `location`, - `post-content`.`coord` AS `coord`, - `post-content`.`app` AS `app`, - `post-content`.`object-type` AS `object-type`, - `post-content`.`object` AS `object`, - `post-content`.`target-type` AS `target-type`, - `post-content`.`target` AS `target`, - `post-content`.`resource-id` AS `resource-id`, - `item`.`contact-id` AS `contact-id`, - `contact`.`url` AS `contact-link`, - `contact`.`addr` AS `contact-addr`, - `contact`.`name` AS `contact-name`, - `contact`.`nick` AS `contact-nick`, - `contact`.`thumb` AS `contact-avatar`, - `contact`.`network` AS `contact-network`, - `contact`.`blocked` AS `contact-blocked`, - `contact`.`hidden` AS `contact-hidden`, - `contact`.`readonly` AS `contact-readonly`, - `contact`.`archive` AS `contact-archive`, - `contact`.`pending` AS `contact-pending`, - `contact`.`rel` AS `contact-rel`, - `contact`.`uid` AS `contact-uid`, - `contact`.`contact-type` AS `contact-contact-type`, - IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`, - `contact`.`self` AS `self`, - `contact`.`id` AS `cid`, - `contact`.`alias` AS `alias`, - `contact`.`photo` AS `photo`, - `contact`.`name-date` AS `name-date`, - `contact`.`uri-date` AS `uri-date`, - `contact`.`avatar-date` AS `avatar-date`, - `contact`.`thumb` AS `thumb`, - `contact`.`dfrn-id` AS `dfrn-id`, - `item`.`author-id` AS `author-id`, - `author`.`url` AS `author-link`, - `author`.`addr` AS `author-addr`, - IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`, - `author`.`nick` AS `author-nick`, - IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`, - `author`.`network` AS `author-network`, - `author`.`blocked` AS `author-blocked`, - `author`.`hidden` AS `author-hidden`, - `item`.`owner-id` AS `owner-id`, - `owner`.`url` AS `owner-link`, - `owner`.`addr` AS `owner-addr`, - IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`, - `owner`.`nick` AS `owner-nick`, - IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`, - `owner`.`network` AS `owner-network`, - `owner`.`blocked` AS `owner-blocked`, - `owner`.`hidden` AS `owner-hidden`, - `item`.`causer-id` AS `causer-id`, - `causer`.`url` AS `causer-link`, - `causer`.`addr` AS `causer-addr`, - `causer`.`name` AS `causer-name`, - `causer`.`nick` AS `causer-nick`, - `causer`.`thumb` AS `causer-avatar`, - `causer`.`network` AS `causer-network`, - `causer`.`blocked` AS `causer-blocked`, - `causer`.`hidden` AS `causer-hidden`, - `causer`.`contact-type` AS `causer-contact-type`, - `post-delivery-data`.`postopts` AS `postopts`, - `post-delivery-data`.`inform` AS `inform`, - `post-delivery-data`.`queue_count` AS `delivery_queue_count`, - `post-delivery-data`.`queue_done` AS `delivery_queue_done`, - `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`, - IF (`item`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`, - IF (`item`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`, - IF (`item`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`, - IF (`item`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`, - `item`.`event-id` AS `event-id`, - `event`.`created` AS `event-created`, - `event`.`edited` AS `event-edited`, - `event`.`start` AS `event-start`, - `event`.`finish` AS `event-finish`, - `event`.`summary` AS `event-summary`, - `event`.`desc` AS `event-desc`, - `event`.`location` AS `event-location`, - `event`.`type` AS `event-type`, - `event`.`nofinish` AS `event-nofinish`, - `event`.`adjust` AS `event-adjust`, - `event`.`ignore` AS `event-ignore`, - `diaspora-interaction`.`interaction` AS `signed_text`, - `parent-item`.`guid` AS `parent-guid`, - `parent-item`.`network` AS `parent-network`, - `parent-item`.`author-id` AS `parent-author-id`, - `parent-item-author`.`url` AS `parent-author-link`, - `parent-item-author`.`name` AS `parent-author-name`, - `parent-item-author`.`network` AS `parent-author-network` - FROM `item` - LEFT JOIN `post-user` ON `post-user`.`uri-id` = `item`.`uri-id` AND `post-user`.`uid` = `item`.`uid` - STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `item`.`author-id` - STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `item`.`owner-id` - STRAIGHT_JOIN `contact` AS `causer` ON `causer`.`id` = `item`.`causer-id` - LEFT JOIN `verb` ON `verb`.`id` = `item`.`vid` - LEFT JOIN `event` ON `event`.`id` = `item`.`event-id` - LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `item`.`uri-id` - LEFT JOIN `post-content` ON `post-content`.`uri-id` = `item`.`uri-id` - LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `item`.`uri-id` AND `item`.`origin` - LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid` - STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`uri-id` = `item`.`parent-uri-id` AND `parent-item`.`uid` = `item`.`uid` - STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id`; - --- --- VIEW post-view2 --- -DROP VIEW IF EXISTS `post-view2`; -CREATE VIEW `post-view2` AS SELECT - `item`.`id` AS `id`, - `item`.`id` AS `item_id`, + `item`.`id` AS `item-id`, `post-user`.`id` AS `post-user-id`, `post-user`.`uid` AS `uid`, `item`.`parent` AS `parent`, + `parent-post`.`id` AS `parent-user-id`, `item-uri`.`uri` AS `uri`, - `post`.`uri-id` AS `uri-id`, + `post-user`.`uri-id` AS `uri-id`, `parent-item-uri`.`uri` AS `parent-uri`, - `post`.`parent-uri-id` AS `parent-uri-id`, + `post-user`.`parent-uri-id` AS `parent-uri-id`, `thr-parent-item-uri`.`uri` AS `thr-parent`, - `post`.`thr-parent-id` AS `thr-parent-id`, + `post-user`.`thr-parent-id` AS `thr-parent-id`, `item-uri`.`guid` AS `guid`, `post-user`.`wall` AS `wall`, - `post`.`gravity` AS `gravity`, - `item`.`extid` AS `extid`, - `post`.`created` AS `created`, - `post`.`edited` AS `edited`, - `post-thread`.`commented` AS `commented`, - `post`.`received` AS `received`, - `post-thread`.`changed` AS `changed`, - `post`.`post-type` AS `post-type`, - `post`.`private` AS `private`, + `post-user`.`gravity` AS `gravity`, + `external-item-uri`.`uri` AS `extid`, + `post-user`.`external-id` AS `external-id`, + `post-user`.`created` AS `created`, + `post-user`.`edited` AS `edited`, + `post-thread-user`.`commented` AS `commented`, + `post-user`.`received` AS `received`, + `post-thread-user`.`changed` AS `changed`, + `post-user`.`post-type` AS `post-type`, + `post-user`.`private` AS `private`, `post-thread-user`.`pubmail` AS `pubmail`, - `post`.`visible` AS `visible`, + `post-user`.`visible` AS `visible`, `post-thread-user`.`starred` AS `starred`, `post-user`.`unseen` AS `unseen`, - `post`.`deleted` AS `deleted`, + `post-user`.`deleted` AS `deleted`, `post-user`.`origin` AS `origin`, `post-thread-user`.`forum_mode` AS `forum_mode`, `post-thread-user`.`mention` AS `mention`, - `post`.`global` AS `global`, - `post`.`network` AS `network`, - `post`.`vid` AS `vid`, + `post-user`.`global` AS `global`, + `post-user`.`network` AS `network`, + `post-user`.`vid` AS `vid`, `post-user`.`psid` AS `psid`, - IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`, + IF (`post-user`.`vid` IS NULL, '', `verb`.`name`) AS `verb`, `post-content`.`title` AS `title`, `post-content`.`content-warning` AS `content-warning`, `post-content`.`raw-body` AS `raw-body`, @@ -1734,7 +1656,7 @@ CREATE VIEW `post-view2` AS SELECT `contact`.`rel` AS `contact-rel`, `contact`.`uid` AS `contact-uid`, `contact`.`contact-type` AS `contact-contact-type`, - IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`, + IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`, `contact`.`self` AS `self`, `contact`.`id` AS `cid`, `contact`.`alias` AS `alias`, @@ -1744,7 +1666,7 @@ CREATE VIEW `post-view2` AS SELECT `contact`.`avatar-date` AS `avatar-date`, `contact`.`thumb` AS `thumb`, `contact`.`dfrn-id` AS `dfrn-id`, - `post`.`author-id` AS `author-id`, + `post-user`.`author-id` AS `author-id`, `author`.`url` AS `author-link`, `author`.`addr` AS `author-addr`, IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`, @@ -1753,7 +1675,7 @@ CREATE VIEW `post-view2` AS SELECT `author`.`network` AS `author-network`, `author`.`blocked` AS `author-blocked`, `author`.`hidden` AS `author-hidden`, - `post`.`owner-id` AS `owner-id`, + `post-user`.`owner-id` AS `owner-id`, `owner`.`url` AS `owner-link`, `owner`.`addr` AS `owner-addr`, IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`, @@ -1762,7 +1684,7 @@ CREATE VIEW `post-view2` AS SELECT `owner`.`network` AS `owner-network`, `owner`.`blocked` AS `owner-blocked`, `owner`.`hidden` AS `owner-hidden`, - `post`.`causer-id` AS `causer-id`, + `post-user`.`causer-id` AS `causer-id`, `causer`.`url` AS `causer-link`, `causer`.`addr` AS `causer-addr`, `causer`.`name` AS `causer-name`, @@ -1797,29 +1719,28 @@ CREATE VIEW `post-view2` AS SELECT `parent-item-uri`.`guid` AS `parent-guid`, `parent-post`.`network` AS `parent-network`, `parent-post`.`author-id` AS `parent-author-id`, - `parent-item-author`.`url` AS `parent-author-link`, - `parent-item-author`.`name` AS `parent-author-name`, - `parent-item-author`.`network` AS `parent-author-network` - FROM `post` - STRAIGHT_JOIN `post-user` ON `post-user`.`uri-id` = `post`.`uri-id` - STRAIGHT_JOIN `post-thread` ON `post-thread`.`uri-id` = `post`.`parent-uri-id` - STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid` - STRAIGHT_JOIN `item` ON `item`.`uri-id` = `post`.`uri-id` AND `item`.`uid` = `post-user`.`uid` - LEFT JOIN `item-uri` ON `item-uri`.`id` = `post`.`uri-id` - LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id` - LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id` - LEFT JOIN `contact` ON `contact`.`id` = `post-user`.`contact-id` - LEFT JOIN `contact` AS `author` ON `author`.`id` = `post`.`author-id` - LEFT JOIN `contact` AS `owner` ON `owner`.`id` = `post`.`owner-id` - LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post`.`causer-id` - LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid` + `parent-post-author`.`url` AS `parent-author-link`, + `parent-post-author`.`name` AS `parent-author-name`, + `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 `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 `event` ON `event`.`id` = `post-user`.`event-id` - LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post`.`uri-id` - LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post`.`uri-id` - LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post`.`uri-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` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id` - LEFT JOIN `contact` AS `parent-item-author` ON `parent-item-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-user`.`uid` + INNER JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`; -- -- VIEW post-thread-view @@ -1827,42 +1748,44 @@ CREATE VIEW `post-view2` AS SELECT DROP VIEW IF EXISTS `post-thread-view`; CREATE VIEW `post-thread-view` AS SELECT `item`.`id` AS `id`, + `item`.`id` AS `item-id`, `item`.`id` AS `iid`, - `item`.`id` AS `item_id`, - `post-thread-user`.`post-user-id` AS `post-user-id`, + `post-user`.`id` AS `post-user-id`, `post-thread-user`.`uid` AS `uid`, `item`.`parent` AS `parent`, + `parent-post`.`id` AS `parent-user-id`, `item-uri`.`uri` AS `uri`, - `post-thread`.`uri-id` AS `uri-id`, + `post-thread-user`.`uri-id` AS `uri-id`, `parent-item-uri`.`uri` AS `parent-uri`, - `post`.`parent-uri-id` AS `parent-uri-id`, + `post-user`.`parent-uri-id` AS `parent-uri-id`, `thr-parent-item-uri`.`uri` AS `thr-parent`, - `post`.`thr-parent-id` AS `thr-parent-id`, + `post-user`.`thr-parent-id` AS `thr-parent-id`, `item-uri`.`guid` AS `guid`, `post-thread-user`.`wall` AS `wall`, - `post`.`gravity` AS `gravity`, - `item`.`extid` AS `extid`, - `post-thread`.`created` AS `created`, - `post`.`edited` AS `edited`, - `post-thread`.`commented` AS `commented`, - `post-thread`.`received` AS `received`, - `post-thread`.`changed` AS `changed`, - `post`.`post-type` AS `post-type`, - `post`.`private` AS `private`, + `post-user`.`gravity` AS `gravity`, + `external-item-uri`.`uri` AS `extid`, + `post-user`.`external-id` AS `external-id`, + `post-thread-user`.`created` AS `created`, + `post-user`.`edited` AS `edited`, + `post-thread-user`.`commented` AS `commented`, + `post-thread-user`.`received` AS `received`, + `post-thread-user`.`changed` AS `changed`, + `post-user`.`post-type` AS `post-type`, + `post-user`.`private` AS `private`, `post-thread-user`.`pubmail` AS `pubmail`, `post-thread-user`.`ignored` AS `ignored`, - `post`.`visible` AS `visible`, + `post-user`.`visible` AS `visible`, `post-thread-user`.`starred` AS `starred`, `post-thread-user`.`unseen` AS `unseen`, - `post`.`deleted` AS `deleted`, + `post-user`.`deleted` AS `deleted`, `post-thread-user`.`origin` AS `origin`, `post-thread-user`.`forum_mode` AS `forum_mode`, `post-thread-user`.`mention` AS `mention`, - `post`.`global` AS `global`, - `post-thread`.`network` AS `network`, - `post`.`vid` AS `vid`, + `post-user`.`global` AS `global`, + `post-thread-user`.`network` AS `network`, + `post-user`.`vid` AS `vid`, `post-thread-user`.`psid` AS `psid`, - IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`, + IF (`post-user`.`vid` IS NULL, '', `verb`.`name`) AS `verb`, `post-content`.`title` AS `title`, `post-content`.`content-warning` AS `content-warning`, `post-content`.`raw-body` AS `raw-body`, @@ -1894,7 +1817,7 @@ CREATE VIEW `post-thread-view` AS SELECT `contact`.`rel` AS `contact-rel`, `contact`.`uid` AS `contact-uid`, `contact`.`contact-type` AS `contact-contact-type`, - IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`, + IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`, `contact`.`self` AS `self`, `contact`.`id` AS `cid`, `contact`.`alias` AS `alias`, @@ -1904,7 +1827,7 @@ CREATE VIEW `post-thread-view` AS SELECT `contact`.`avatar-date` AS `avatar-date`, `contact`.`thumb` AS `thumb`, `contact`.`dfrn-id` AS `dfrn-id`, - `post-thread`.`author-id` AS `author-id`, + `post-thread-user`.`author-id` AS `author-id`, `author`.`url` AS `author-link`, `author`.`addr` AS `author-addr`, IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`, @@ -1913,7 +1836,7 @@ CREATE VIEW `post-thread-view` AS SELECT `author`.`network` AS `author-network`, `author`.`blocked` AS `author-blocked`, `author`.`hidden` AS `author-hidden`, - `post-thread`.`owner-id` AS `owner-id`, + `post-thread-user`.`owner-id` AS `owner-id`, `owner`.`url` AS `owner-link`, `owner`.`addr` AS `owner-addr`, IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`, @@ -1922,7 +1845,7 @@ CREATE VIEW `post-thread-view` AS SELECT `owner`.`network` AS `owner-network`, `owner`.`blocked` AS `owner-blocked`, `owner`.`hidden` AS `owner-hidden`, - `post-thread`.`causer-id` AS `causer-id`, + `post-thread-user`.`causer-id` AS `causer-id`, `causer`.`url` AS `causer-link`, `causer`.`addr` AS `causer-addr`, `causer`.`name` AS `causer-name`, @@ -1957,29 +1880,28 @@ CREATE VIEW `post-thread-view` AS SELECT `parent-item-uri`.`guid` AS `parent-guid`, `parent-post`.`network` AS `parent-network`, `parent-post`.`author-id` AS `parent-author-id`, - `parent-item-author`.`url` AS `parent-author-link`, - `parent-item-author`.`name` AS `parent-author-name`, - `parent-item-author`.`network` AS `parent-author-network` - FROM `post-thread` - STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-thread`.`uri-id` - STRAIGHT_JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id` - STRAIGHT_JOIN `post` ON `post`.`uri-id` = `post-thread`.`uri-id` - LEFT JOIN `item-uri` ON `item-uri`.`id` = `post`.`uri-id` - LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id` - LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id` - LEFT JOIN `item` ON `item`.`uri-id` = `post-thread`.`uri-id` AND `item`.`uid` = `post-thread-user`.`uid` - LEFT JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id` - LEFT JOIN `contact` AS `author` ON `author`.`id` = `post-thread`.`author-id` - LEFT JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread`.`owner-id` - LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread`.`causer-id` - LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid` + `parent-post-author`.`url` AS `parent-author-link`, + `parent-post-author`.`name` AS `parent-author-name`, + `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 `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 `event` ON `event`.`id` = `post-user`.`event-id` - LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread`.`uri-id` - LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread`.`uri-id` - LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-thread`.`uri-id` AND `post-thread-user`.`origin` + 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` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id` - LEFT JOIN `contact` AS `parent-item-author` ON `parent-item-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-user`.`uid` + INNER JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`; -- -- VIEW category-view @@ -1988,14 +1910,11 @@ DROP VIEW IF EXISTS `category-view`; CREATE VIEW `category-view` AS SELECT `post-category`.`uri-id` AS `uri-id`, `post-category`.`uid` AS `uid`, - `item-uri`.`uri` AS `uri`, - `item-uri`.`guid` AS `guid`, `post-category`.`type` AS `type`, `post-category`.`tid` AS `tid`, `tag`.`name` AS `name`, `tag`.`url` AS `url` FROM `post-category` - INNER JOIN `item-uri` ON `item-uri`.id = `post-category`.`uri-id` LEFT JOIN `tag` ON `post-category`.`tid` = `tag`.`id`; -- @@ -2004,15 +1923,12 @@ CREATE VIEW `category-view` AS SELECT DROP VIEW IF EXISTS `tag-view`; CREATE VIEW `tag-view` AS SELECT `post-tag`.`uri-id` AS `uri-id`, - `item-uri`.`uri` AS `uri`, - `item-uri`.`guid` AS `guid`, `post-tag`.`type` AS `type`, `post-tag`.`tid` AS `tid`, `post-tag`.`cid` AS `cid`, CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END AS `name`, CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END AS `url` FROM `post-tag` - INNER JOIN `item-uri` ON `item-uri`.id = `post-tag`.`uri-id` LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id` LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`; @@ -2021,28 +1937,28 @@ CREATE VIEW `tag-view` AS SELECT -- DROP VIEW IF EXISTS `network-item-view`; CREATE VIEW `network-item-view` AS SELECT - `item`.`parent-uri-id` AS `uri-id`, - `item`.`parent-uri` AS `uri`, + `post-user`.`uri-id` AS `uri-id`, `item`.`parent` AS `parent`, - `item`.`received` AS `received`, - `item`.`commented` AS `commented`, - `item`.`created` AS `created`, - `item`.`uid` AS `uid`, - `item`.`starred` AS `starred`, - `item`.`mention` AS `mention`, - `item`.`network` AS `network`, - `item`.`unseen` AS `unseen`, - `item`.`gravity` AS `gravity`, - `item`.`contact-id` AS `contact-id`, + `post-user`.`parent-uri-id` AS `parent-uri-id`, + `post-user`.`received` AS `received`, + `post-thread-user`.`commented` AS `commented`, + `post-user`.`created` AS `created`, + `post-user`.`uid` AS `uid`, + `post-thread-user`.`starred` AS `starred`, + `post-thread-user`.`mention` AS `mention`, + `post-user`.`network` AS `network`, + `post-user`.`unseen` AS `unseen`, + `post-user`.`gravity` AS `gravity`, + `post-user`.`contact-id` AS `contact-id`, `ownercontact`.`contact-type` AS `contact-type` - FROM `item` - INNER JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent` - STRAIGHT_JOIN `contact` ON `contact`.`id` = `parent-item`.`contact-id` - LEFT JOIN `post-user` ON `post-user`.`uri-id` = `item`.`uri-id` AND `post-user`.`uid` = `parent-item`.`uid` - LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `parent-item`.`uid` AND `author`.`cid` = `parent-item`.`author-id` - LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `parent-item`.`uid` AND `owner`.`cid` = `parent-item`.`owner-id` - LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `parent-item`.`owner-id` - WHERE `parent-item`.`visible` AND NOT `parent-item`.`deleted` + 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-thread-user`.`contact-id` + LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id` + LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id` + INNER JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id` + WHERE `post-user`.`visible` AND NOT `post-user`.`deleted` AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`) AND (`post-user`.`hidden` IS NULL OR NOT `post-user`.`hidden`) AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`) @@ -2053,27 +1969,26 @@ CREATE VIEW `network-item-view` AS SELECT -- DROP VIEW IF EXISTS `network-thread-view`; CREATE VIEW `network-thread-view` AS SELECT - `post-thread`.`uri-id` AS `uri-id`, - `item`.`uri` AS `uri`, - `item`.`parent-uri-id` AS `parent-uri-id`, + `post-thread-user`.`uri-id` AS `uri-id`, + `post-user`.`parent-uri-id` AS `parent-uri-id`, `item`.`id` AS `parent`, - `post-thread`.`received` AS `received`, - `post-thread`.`commented` AS `commented`, - `post-thread`.`created` AS `created`, + `post-thread-user`.`received` AS `received`, + `post-thread-user`.`commented` AS `commented`, + `post-thread-user`.`created` AS `created`, `post-thread-user`.`uid` AS `uid`, `post-thread-user`.`starred` AS `starred`, `post-thread-user`.`mention` AS `mention`, - `post-thread`.`network` AS `network`, + `post-thread-user`.`network` AS `network`, `post-thread-user`.`contact-id` AS `contact-id`, `ownercontact`.`contact-type` AS `contact-type` - FROM `post-thread` - STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-thread`.`uri-id` - STRAIGHT_JOIN `item` ON `item`.`uri-id` = `post-thread`.`uri-id` AND `item`.`uid` = `post-thread-user`.`uid` + 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` STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id` - LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread`.`author-id` - LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread`.`owner-id` - LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread`.`owner-id` - WHERE `item`.`visible` AND NOT `item`.`deleted` + LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id` + LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id` + LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id` + WHERE `post-user`.`visible` AND NOT `post-user`.`deleted` AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`) AND (`post-thread-user`.`hidden` IS NULL OR NOT `post-thread-user`.`hidden`) AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`) @@ -2242,19 +2157,16 @@ CREATE VIEW `pending-view` AS SELECT DROP VIEW IF EXISTS `tag-search-view`; CREATE VIEW `tag-search-view` AS SELECT `post-tag`.`uri-id` AS `uri-id`, - `item`.`id` AS `iid`, - `item`.`uri` AS `uri`, - `item`.`guid` AS `guid`, - `item`.`uid` AS `uid`, - `item`.`private` AS `private`, - `item`.`wall` AS `wall`, - `item`.`origin` AS `origin`, - `item`.`gravity` AS `gravity`, - `item`.`received` AS `received`, + `post-user`.`uid` AS `uid`, + `post-user`.`private` AS `private`, + `post-user`.`wall` AS `wall`, + `post-user`.`origin` AS `origin`, + `post-user`.`gravity` AS `gravity`, + `post-user`.`received` AS `received`, `tag`.`name` AS `name` FROM `post-tag` INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid` - INNER JOIN `item` ON `item`.`uri-id` = `post-tag`.`uri-id` + STRAIGHT_JOIN `post-user` ON `post-user`.`uri-id` = `post-tag`.`uri-id` WHERE `post-tag`.`type` = 1; -- diff --git a/mod/item.php b/mod/item.php index 0c252cd6c..d180cb08a 100644 --- a/mod/item.php +++ b/mod/item.php @@ -651,7 +651,6 @@ function item_post(App $a) { // doesn't have an ID. $datarray["id"] = -1; $datarray["uri-id"] = -1; - $datarray["item_id"] = -1; $datarray["author-network"] = Protocol::DFRN; $o = conversation($a, [array_merge($contact_record, $datarray)], 'search', false, true); diff --git a/src/Model/Item.php b/src/Model/Item.php index 6114457d6..814696a49 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -77,7 +77,7 @@ class Item 'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink', 'wall', 'private', 'starred', 'origin', 'title', 'body', 'language', 'content-warning', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object', - 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'item_id', + 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network', 'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'owner-network', 'causer-id', 'causer-link', 'causer-name', 'causer-avatar', 'causer-contact-type', @@ -959,6 +959,10 @@ class Item $item['deny_gid'] ); + if (!empty($item['extid'])) { + $item['external-id'] = ItemURI::getIdByURI($item['extid']); + } + if ($item['verb'] == Activity::ANNOUNCE) { self::setOwnerforResharedItem($item); } diff --git a/src/Model/Post.php b/src/Model/Post.php index 30515d711..4f06babf9 100644 --- a/src/Model/Post.php +++ b/src/Model/Post.php @@ -94,6 +94,10 @@ class Post } } + if (array_key_exists('extid', $row) && is_null($row['extid'])) { + $row['extid'] = ''; + } + return $row; } @@ -526,8 +530,8 @@ class Post } } if (!empty($update_fields)) { - $rows = DBA::selectToArray('post-view', ['id'], $condition, []); - $ids = array_column($rows, 'id'); + $rows = DBA::selectToArray('post-view', ['item-id'], $condition, []); + $ids = array_column($rows, 'item-id'); if (!DBA::update('item', $update_fields, ['id' => $ids])) { DBA::rollback(); Logger::notice('Updating item failed', ['fields' => $update_fields, 'condition' => $condition]); diff --git a/src/Worker/CleanItemUri.php b/src/Worker/CleanItemUri.php index 268fe29dc..8f74d99fb 100644 --- a/src/Worker/CleanItemUri.php +++ b/src/Worker/CleanItemUri.php @@ -42,9 +42,10 @@ class CleanItemUri } 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`)", $item['uri-id']); + AND NOT EXISTS(SELECT `uri-id` FROM `post-user` WHERE `uri-id` = `item-uri`.`id`) + AND NOT EXISTS(SELECT `parent-uri-id` FROM `post-user` WHERE `parent-uri-id` = `item-uri`.`id`) + AND NOT EXISTS(SELECT `thr-parent-id` FROM `post-user` WHERE `thr-parent-id` = `item-uri`.`id`) + AND NOT EXISTS(SELECT `external-id` FROM `post-user` WHERE `external-id` = `item-uri`.`id`)", $item['uri-id']); Logger::notice('Orphaned URI-ID entries removed', ['result' => $ret, 'rows' => DBA::affectedRows()]); } } diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index acb5132af..93e0215f7 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -111,9 +111,6 @@ class Cron // update nodeinfo data Worker::add(PRIORITY_LOW, 'NodeInfo'); - // Repair entries in the database - Worker::add(PRIORITY_LOW, 'RepairDatabase'); - Worker::add(PRIORITY_LOW, 'Expire'); Worker::add(PRIORITY_LOW, 'ExpirePosts'); diff --git a/src/Worker/Expire.php b/src/Worker/Expire.php index ca92bd1ee..31c0af039 100644 --- a/src/Worker/Expire.php +++ b/src/Worker/Expire.php @@ -55,21 +55,16 @@ class Expire Logger::info('Deleting orphaned post-content - start'); /// @todo Replace "item with "post-user" in the future when "item" is removed - $condition = ["NOT EXISTS (SELECT `uri-id` FROM `item` WHERE `item`.`uri-id` = `post-content`.`uri-id`)"]; + $condition = ["NOT EXISTS (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uri-id` = `post-content`.`uri-id`)"]; DBA::delete('post-content', $condition); Logger::info('Orphaned post-content deleted', ['rows' => DBA::affectedRows()]); Logger::info('Deleting orphaned post-thread - start'); /// @todo Replace "item with "post-user" in the future when "item" is removed - $condition = ["NOT EXISTS (SELECT `uri-id` FROM `item` WHERE `item`.`uri-id` = `post-thread`.`uri-id`)"]; + $condition = ["NOT EXISTS (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uri-id` = `post-thread`.`uri-id`)"]; DBA::delete('post-thread', $condition); Logger::info('Orphaned item content deleted', ['rows' => DBA::affectedRows()]); - // make this optional as it could have a performance impact on large sites - if (intval(DI::config()->get('system', 'optimize_items'))) { - DBA::e("OPTIMIZE TABLE `item`"); - } - Logger::log('Delete expired items - done', Logger::DEBUG); return; } elseif (intval($param) > 0) { diff --git a/src/Worker/ExpirePosts.php b/src/Worker/ExpirePosts.php index 61343566d..0535c223b 100644 --- a/src/Worker/ExpirePosts.php +++ b/src/Worker/ExpirePosts.php @@ -50,15 +50,18 @@ class ExpirePosts Logger::notice('Start deleting expired threads', ['expiry_days' => $expire_days]); $ret = DBA::e("DELETE FROM `item-uri` WHERE `id` IN (SELECT `uri-id` FROM `post-thread` WHERE `received` < UTC_TIMESTAMP() - INTERVAL ? DAY - AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-thread-user` WHERE (`mention` OR `starred` OR `wall` OR `pinned`) AND `uri-id` = `post-thread`.`uri-id`) - AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin` AND `uri-id` = `post-thread`.`uri-id`) - AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-category` WHERE `uri-id` = `post-thread`.`uri-id`) - AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-media` WHERE `uri-id` = `post-thread`.`uri-id`) - AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `item` INNER JOIN `contact` ON `contact`.`id` = `contact-id` AND `notify_new_posts` + AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-thread-user` + WHERE (`mention` OR `starred` OR `wall` OR `pinned`) AND `uri-id` = `post-thread`.`uri-id`) + AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-category` + WHERE `uri-id` = `post-thread`.`uri-id`) + AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-media` + WHERE `uri-id` = `post-thread`.`uri-id`) + AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `post-user` INNER JOIN `contact` ON `contact`.`id` = `contact-id` AND `notify_new_posts` WHERE `parent-uri-id` = `post-thread`.`uri-id`) - AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `item` - WHERE (`origin` OR `starred` OR `resource-id` != 0 OR `event-id` != 0 OR `wall` OR `attach` != '' OR `post-type` = ?) - AND `parent-uri-id` = `post-thread`.`uri-id`)) + AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `post-user` + WHERE (`origin` OR `event-id` != 0 OR `post-type` = ?) AND `parent-uri-id` = `post-thread`.`uri-id`)) + AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-content` + WHERE (`resource-id` != 0) AND `uri-id` = `post-thread`.`uri-id`)) ORDER BY `id` LIMIT ?", $expire_days, Item::PT_PERSONAL_NOTE, $limit); $rows = DBA::affectedRows(); @@ -75,11 +78,11 @@ class ExpirePosts do { Logger::notice('Start deleting unclaimed public items', ['expiry_days' => $expire_days_unclaimed]); $ret = DBA::e("DELETE FROM `item-uri` WHERE `id` IN - (SELECT `uri-id` FROM `item` WHERE `gravity` = ? AND `uid` = ? AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY - AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `item` AS `i` WHERE `i`.`uid` != ? - AND `i`.`parent-uri-id` = `item`.`uri-id`) - AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `item` AS `i` WHERE `i`.`uid` = ? - AND `i`.`parent-uri-id` = `item`.`uri-id` AND `i`.`received` > UTC_TIMESTAMP() - INTERVAL ? DAY)) + (SELECT `uri-id` FROM `post-user` WHERE `gravity` = ? AND `uid` = ? AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY + AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `post-user` AS `i` WHERE `i`.`uid` != ? + AND `i`.`parent-uri-id` = `post-user`.`uri-id`) + AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `post-user` AS `i` WHERE `i`.`uid` = ? + AND `i`.`parent-uri-id` = `post-user`.`uri-id` AND `i`.`received` > UTC_TIMESTAMP() - INTERVAL ? DAY)) ORDER BY `id` LIMIT ?", GRAVITY_PARENT, 0, $expire_days_unclaimed, 0, 0, $expire_days_unclaimed, $limit); diff --git a/src/Worker/RemoveUnusedAvatars.php b/src/Worker/RemoveUnusedAvatars.php index 0d9c0f6fb..bbfd3fdf8 100644 --- a/src/Worker/RemoveUnusedAvatars.php +++ b/src/Worker/RemoveUnusedAvatars.php @@ -35,9 +35,9 @@ class RemoveUnusedAvatars public static function execute() { $condition = ["`uid` = ? AND NOT `self` AND NOT `nurl` IN (SELECT `nurl` FROM `contact` WHERE `uid` != ?) - AND `id` IN (SELECT `contact-id` FROM `photo`) AND NOT `id` IN (SELECT `author-id` FROM `item`) - AND NOT `id` IN (SELECT `owner-id` FROM `item`) AND NOT `id` IN (SELECT `causer-id` FROM `item`) - AND NOT `id` IN (SELECT `cid` FROM `post-tag`) AND NOT `id` IN (SELECT `contact-id` FROM `item`)", 0, 0]; + AND `id` IN (SELECT `contact-id` FROM `photo`) AND NOT `id` IN (SELECT `author-id` FROM `post-user`) + AND NOT `id` IN (SELECT `owner-id` FROM `post-user`) AND NOT `id` IN (SELECT `causer-id` FROM `post-user`) + AND NOT `id` IN (SELECT `cid` FROM `post-tag`) AND NOT `id` IN (SELECT `contact-id` FROM `post-user`)", 0, 0]; $total = DBA::count('contact', $condition); Logger::notice('Starting removal', ['total' => $total]); diff --git a/src/Worker/RemoveUnusedContacts.php b/src/Worker/RemoveUnusedContacts.php index f90abe369..a781a490a 100644 --- a/src/Worker/RemoveUnusedContacts.php +++ b/src/Worker/RemoveUnusedContacts.php @@ -36,11 +36,9 @@ class RemoveUnusedContacts { $condition = ["`uid` = ? AND NOT `self` AND NOT `nurl` IN (SELECT `nurl` FROM `contact` WHERE `uid` != ?) AND (NOT `network` IN (?, ?, ?, ?, ?, ?) OR (`archive` AND `success_update` < UTC_TIMESTAMP() - INTERVAL ? DAY)) - AND NOT `id` IN (SELECT `author-id` FROM `item`) AND NOT `id` IN (SELECT `owner-id` FROM `item`) - AND NOT `id` IN (SELECT `causer-id` FROM `item`) AND NOT `id` IN (SELECT `cid` FROM `post-tag`) - AND NOT `id` IN (SELECT `contact-id` FROM `item`) AND NOT `id` IN (SELECT `author-id` FROM `post-thread`) - AND NOT `id` IN (SELECT `owner-id` FROM `post-thread`) AND NOT `id` IN (SELECT `causer-id` FROM `post-thread`) - AND NOT `id` IN (SELECT `contact-id` FROM `post-user`) AND NOT `id` IN (SELECT `cid` FROM `user-contact`) + AND NOT `id` IN (SELECT `author-id` FROM `post-user`) AND NOT `id` IN (SELECT `owner-id` FROM `post-user`) + AND NOT `id` IN (SELECT `causer-id` FROM `post-user`) AND NOT `id` IN (SELECT `cid` FROM `post-tag`) + AND NOT `id` IN (SELECT `contact-id` FROM `post-user`) AND NOT `id` IN (SELECT `cid` FROM `user-contact`) AND NOT `id` IN (SELECT `cid` FROM `event`) AND NOT `id` IN (SELECT `contact-id` FROM `group_member`)", 0, 0, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL, Protocol::ACTIVITYPUB, 365]; @@ -54,6 +52,26 @@ class RemoveUnusedContacts DBA::delete('thread', ['owner-id' => $contact['id']]); DBA::delete('thread', ['author-id' => $contact['id']]); } + if (DBStructure::existsTable('item')) { + DBA::delete('item', ['owner-id' => $contact['id']]); + DBA::delete('item', ['author-id' => $contact['id']]); + DBA::delete('item', ['causer-id' => $contact['id']]); + } + + // There should be none entry for the contact in these tables when none was found in "post-user". + // But we want to be sure since the foreign key prohibits deletion otherwise. + DBA::delete('post', ['owner-id' => $contact['id']]); + DBA::delete('post', ['author-id' => $contact['id']]); + DBA::delete('post', ['causer-id' => $contact['id']]); + + DBA::delete('post-thread', ['owner-id' => $contact['id']]); + DBA::delete('post-thread', ['author-id' => $contact['id']]); + DBA::delete('post-thread', ['causer-id' => $contact['id']]); + + DBA::delete('post-thread-user', ['owner-id' => $contact['id']]); + DBA::delete('post-thread-user', ['author-id' => $contact['id']]); + DBA::delete('post-thread-user', ['causer-id' => $contact['id']]); + DBA::delete('contact', ['id' => $contact['id']]); if ((++$count % 1000) == 0) { Logger::notice('In removal', ['count' => $count, 'total' => $total]); diff --git a/src/Worker/RepairDatabase.php b/src/Worker/RepairDatabase.php deleted file mode 100644 index ef9035d89..000000000 --- a/src/Worker/RepairDatabase.php +++ /dev/null @@ -1,68 +0,0 @@ -. - * - */ - -namespace Friendica\Worker; - -use Friendica\Database\DBA; -use Friendica\Model\ItemURI; - -/** - * Do some repairs in database entries - * @todo This class can be deleted without replacement when the item table is removed - */ -class RepairDatabase -{ - public static function execute() - { - // Ensure that there are no "uri-id", "parent-uri-id" or "thr-parent-id" fields that are NULL - $items = DBA::select('item', ['id', 'uri', 'guid'], ["`uri-id` IS NULL"]); - while ($item = DBA::fetch($items)) { - $uriid = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]); - DBA::update('item', ['uri-id' => $uriid], ['id' => $item['id']]); - } - DBA::close($items); - - $items = DBA::select('item', ['id', 'parent-uri'], ["`parent-uri-id` IS NULL"]); - while ($item = DBA::fetch($items)) { - $uriid = ItemURI::getIdByURI($item['parent-uri']); - DBA::update('item', ['parent-uri-id' => $uriid], ['id' => $item['id']]); - } - DBA::close($items); - - $items = DBA::select('item', ['id', 'thr-parent'], ["`thr-parent-id` IS NULL"]); - while ($item = DBA::fetch($items)) { - $uriid = ItemURI::getIdByURI($item['thr-parent']); - DBA::update('item', ['thr-parent-id' => $uriid], ['id' => $item['id']]); - } - DBA::close($items); - - // Ensure that all uri-id are set correctly - DBA::e("UPDATE `item` INNER JOIN `item-uri` ON `item-uri`.`uri` = `item`.`uri` - SET `uri-id` = `item-uri`.`id` WHERE `item`.`uri-id` != `item-uri`.`id` AND `item`.`uri` != ?", ''); - DBA::e("UPDATE `item` INNER JOIN `item-uri` ON `item-uri`.`uri` = `item`.`parent-uri` - SET `parent-uri-id` = `item-uri`.`id` WHERE `item`.`parent-uri-id` != `item-uri`.`id` AND `item`.`parent-uri` != ?", ''); - DBA::e("UPDATE `item` INNER JOIN `item-uri` ON `item-uri`.`uri` = `item`.`thr-parent` - SET `thr-parent-id` = `item-uri`.`id` WHERE `item`.`thr-parent-id` != `item-uri`.`id` AND `item`.`thr-parent` != ?", ''); - - // Delete orphaned data from notify table. - DBA::e("DELETE FROM `notify` WHERE NOT `type` IN (1, 2, 16, 32, 512) AND NOT `iid` IN (SELECT `id` FROM `item`)"); - } -} diff --git a/src/Worker/UpdateContacts.php b/src/Worker/UpdateContacts.php index c1f38a3b4..699e0f5ab 100644 --- a/src/Worker/UpdateContacts.php +++ b/src/Worker/UpdateContacts.php @@ -51,8 +51,8 @@ class UpdateContacts // Add every contact our system interacted with and hadn't been updated for a week if unarchived // or for a month if archived. - $condition = DBA::mergeConditions($base_condition, ["(`id` IN (SELECT `author-id` FROM `item`) OR - `id` IN (SELECT `owner-id` FROM `item`) OR `id` IN (SELECT `causer-id` FROM `item`) OR + $condition = DBA::mergeConditions($base_condition, ["(`id` IN (SELECT `author-id` FROM `post-user`) OR + `id` IN (SELECT `owner-id` FROM `post-user`) OR `id` IN (SELECT `causer-id` FROM `post-user`) OR `id` IN (SELECT `cid` FROM `post-tag`) OR `id` IN (SELECT `cid` FROM `user-contact`) OR `uid` != ?) AND (`last-update` < ? OR (NOT `archive` AND `last-update` < ?))", 0, DateTimeFormat::utc('now - 1 month'), DateTimeFormat::utc('now - 1 week')]); diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index b91cd8a93..f61262105 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -1092,6 +1092,7 @@ return [ "uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"], "parent-uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table that contains the 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"], + "external-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the external 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)"], "received" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "datetime"], @@ -1111,6 +1112,7 @@ return [ "PRIMARY" => ["uri-id"], "parent-uri-id" => ["parent-uri-id"], "thr-parent-id" => ["thr-parent-id"], + "external-id" => ["external-id"], "owner-id" => ["owner-id"], "author-id" => ["author-id"], "causer-id" => ["causer-id"], @@ -1243,6 +1245,7 @@ return [ "uri-id" => ["type" => "int unsigned", "not null" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"], "parent-uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table that contains the 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"], + "external-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the external 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)"], "received" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "datetime"], @@ -1279,6 +1282,7 @@ return [ "uid_wall" => ["uid", "wall"], "parent-uri-id" => ["parent-uri-id"], "thr-parent-id" => ["thr-parent-id"], + "external-id" => ["external-id"], "owner-id" => ["owner-id"], "author-id" => ["author-id"], "causer-id" => ["causer-id"], diff --git a/static/dbview.config.php b/static/dbview.config.php index cd1e81d32..eba31db6a 100644 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -40,10 +40,11 @@ "post-view" => [ "fields" => [ "id" => ["item", "id"], - "item_id" => ["item", "id"], + "item-id" => ["item", "id"], "post-user-id" => ["post-user", "id"], "uid" => ["post-user", "uid"], "parent" => ["item", "parent"], + "parent-user-id" => ["parent-post", "id"], "uri" => ["item-uri", "uri"], "uri-id" => ["post-user", "uri-id"], "parent-uri" => ["parent-item-uri", "uri"], @@ -53,7 +54,8 @@ "guid" => ["item-uri", "guid"], "wall" => ["post-user", "wall"], "gravity" => ["post-user", "gravity"], - "extid" => ["item", "extid"], + "extid" => ["external-item-uri", "uri"], + "external-id" => ["post-user", "external-id"], "created" => ["post-user", "created"], "edited" => ["post-user", "edited"], "commented" => ["post-thread-user", "commented"], @@ -182,11 +184,12 @@ 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 `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 `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` + 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`" @@ -194,10 +197,12 @@ "post-thread-view" => [ "fields" => [ "id" => ["item", "id"], + "item-id" => ["item", "id"], "iid" => ["item", "id"], - "item_id" => ["item", "id"], + "post-user-id" => ["post-user", "id"], "uid" => ["post-thread-user", "uid"], "parent" => ["item", "parent"], + "parent-user-id" => ["parent-post", "id"], "uri" => ["item-uri", "uri"], "uri-id" => ["post-thread-user", "uri-id"], "parent-uri" => ["parent-item-uri", "uri"], @@ -207,7 +212,8 @@ "guid" => ["item-uri", "guid"], "wall" => ["post-thread-user", "wall"], "gravity" => ["post-user", "gravity"], - "extid" => ["item", "extid"], + "extid" => ["external-item-uri", "uri"], + "external-id" => ["post-user", "external-id"], "created" => ["post-thread-user", "created"], "edited" => ["post-user", "edited"], "commented" => ["post-thread-user", "commented"], @@ -329,15 +335,16 @@ ], "query" => "FROM `post-thread-user` INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id` - INNER JOIN `item` ON `item`.`uri-id` = `post-thread-user`.`uri-id` AND `item`.`uid` = `post-thread-user`.`uid` + 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` - 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 `verb` ON `verb`.`id` = `post-user`.`vid` + 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 `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 `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` @@ -350,22 +357,17 @@ "fields" => [ "uri-id" => ["post-category", "uri-id"], "uid" => ["post-category", "uid"], - "uri" => ["item-uri", "uri"], - "guid" => ["item-uri", "guid"], "type" => ["post-category", "type"], "tid" => ["post-category", "tid"], "name" => ["tag", "name"], "url" => ["tag", "url"], ], "query" => "FROM `post-category` - INNER JOIN `item-uri` ON `item-uri`.id = `post-category`.`uri-id` LEFT JOIN `tag` ON `post-category`.`tid` = `tag`.`id`" ], "tag-view" => [ "fields" => [ "uri-id" => ["post-tag", "uri-id"], - "uri" => ["item-uri", "uri"], - "guid" => ["item-uri", "guid"], "type" => ["post-tag", "type"], "tid" => ["post-tag", "tid"], "cid" => ["post-tag", "cid"], @@ -373,35 +375,34 @@ "url" => "CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END", ], "query" => "FROM `post-tag` - INNER JOIN `item-uri` ON `item-uri`.id = `post-tag`.`uri-id` LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id` LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`" ], "network-item-view" => [ "fields" => [ - "uri-id" => ["item", "parent-uri-id"], - "uri" => ["item", "parent-uri"], + "uri-id" => ["post-user", "uri-id"], "parent" => ["item", "parent"], - "received" => ["item", "received"], - "commented" => ["item", "commented"], - "created" => ["item", "created"], - "uid" => ["item", "uid"], - "starred" => ["item", "starred"], - "mention" => ["item", "mention"], - "network" => ["item", "network"], - "unseen" => ["item", "unseen"], - "gravity" => ["item", "gravity"], - "contact-id" => ["item", "contact-id"], + "parent-uri-id" => ["post-user", "parent-uri-id"], + "received" => ["post-user", "received"], + "commented" => ["post-thread-user", "commented"], + "created" => ["post-user", "created"], + "uid" => ["post-user", "uid"], + "starred" => ["post-thread-user", "starred"], + "mention" => ["post-thread-user", "mention"], + "network" => ["post-user", "network"], + "unseen" => ["post-user", "unseen"], + "gravity" => ["post-user", "gravity"], + "contact-id" => ["post-user", "contact-id"], "contact-type" => ["ownercontact", "contact-type"], ], - "query" => "FROM `item` - INNER JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent` - STRAIGHT_JOIN `contact` ON `contact`.`id` = `parent-item`.`contact-id` - LEFT JOIN `post-user` ON `post-user`.`uri-id` = `item`.`uri-id` AND `post-user`.`uid` = `parent-item`.`uid` - LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `parent-item`.`uid` AND `author`.`cid` = `parent-item`.`author-id` - LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `parent-item`.`uid` AND `owner`.`cid` = `parent-item`.`owner-id` - LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `parent-item`.`owner-id` - WHERE `parent-item`.`visible` AND NOT `parent-item`.`deleted` + "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-thread-user`.`contact-id` + LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id` + LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id` + INNER JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id` + WHERE `post-user`.`visible` AND NOT `post-user`.`deleted` AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`) AND (`post-user`.`hidden` IS NULL OR NOT `post-user`.`hidden`) AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`) @@ -409,28 +410,27 @@ ], "network-thread-view" => [ "fields" => [ - "uri-id" => ["post-thread", "uri-id"], - "uri" => ["item", "uri"], - "parent-uri-id" => ["item", "parent-uri-id"], + "uri-id" => ["post-thread-user", "uri-id"], + "parent-uri-id" => ["post-user", "parent-uri-id"], "parent" => ["item", "id"], - "received" => ["post-thread", "received"], - "commented" => ["post-thread", "commented"], - "created" => ["post-thread", "created"], + "received" => ["post-thread-user", "received"], + "commented" => ["post-thread-user", "commented"], + "created" => ["post-thread-user", "created"], "uid" => ["post-thread-user", "uid"], "starred" => ["post-thread-user", "starred"], "mention" => ["post-thread-user", "mention"], - "network" => ["post-thread", "network"], + "network" => ["post-thread-user", "network"], "contact-id" => ["post-thread-user", "contact-id"], "contact-type" => ["ownercontact", "contact-type"], ], - "query" => "FROM `post-thread` - STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-thread`.`uri-id` - STRAIGHT_JOIN `item` ON `item`.`uri-id` = `post-thread`.`uri-id` AND `item`.`uid` = `post-thread-user`.`uid` + "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` STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id` - LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread`.`author-id` - LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread`.`owner-id` - LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread`.`owner-id` - WHERE `item`.`visible` AND NOT `item`.`deleted` + LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id` + LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id` + LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id` + WHERE `post-user`.`visible` AND NOT `post-user`.`deleted` AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`) AND (`post-thread-user`.`hidden` IS NULL OR NOT `post-thread-user`.`hidden`) AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`) @@ -592,20 +592,17 @@ "tag-search-view" => [ "fields" => [ "uri-id" => ["post-tag", "uri-id"], - "iid" => ["item", "id"], - "uri" => ["item", "uri"], - "guid" => ["item", "guid"], - "uid" => ["item", "uid"], - "private" => ["item", "private"], - "wall" => ["item", "wall"], - "origin" => ["item", "origin"], - "gravity" => ["item", "gravity"], - "received" => ["item", "received"], + "uid" => ["post-user", "uid"], + "private" => ["post-user", "private"], + "wall" => ["post-user", "wall"], + "origin" => ["post-user", "origin"], + "gravity" => ["post-user", "gravity"], + "received" => ["post-user", "received"], "name" => ["tag", "name"], ], "query" => "FROM `post-tag` INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid` - INNER JOIN `item` ON `item`.`uri-id` = `post-tag`.`uri-id` + STRAIGHT_JOIN `post-user` ON `post-user`.`uri-id` = `post-tag`.`uri-id` WHERE `post-tag`.`type` = 1" ], "workerqueue-view" => [ diff --git a/static/defaults.config.php b/static/defaults.config.php index e11e4c5c8..91a048b94 100644 --- a/static/defaults.config.php +++ b/static/defaults.config.php @@ -405,10 +405,6 @@ return [ // Don't show smilies. 'no_smilies' => false, - // optimize_items (Boolean) - // Triggers an SQL command to optimize the item table before expiring items. - 'optimize_items' => false, - // paranoia (Boolean) // Log out users if their IP address changed. 'paranoia' => false, From 6e1483545e432355178c4dfabf9db601f3b856c0 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 14 Feb 2021 14:24:48 +0000 Subject: [PATCH 03/25] Support for message delivering via uri-id --- mod/events.php | 4 ++-- mod/item.php | 2 +- mod/tagger.php | 4 +++- src/Core/System.php | 6 +++++ src/Model/Event.php | 27 +++++++++++---------- src/Model/Item.php | 9 +++---- src/Model/Post.php | 9 +------ src/Worker/APDelivery.php | 24 +++++++++++++------ src/Worker/Delivery.php | 16 +++++++++++-- src/Worker/Notifier.php | 50 ++++++++++++++++++++++++--------------- 10 files changed, 95 insertions(+), 56 deletions(-) diff --git a/mod/events.php b/mod/events.php index 291535df3..50ffd41a4 100644 --- a/mod/events.php +++ b/mod/events.php @@ -216,10 +216,10 @@ function events_post(App $a) exit(); } - $item_id = Event::store($datarray); + $uri_id = Event::store($datarray); if (!$cid) { - Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $item_id); + Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, (int)$uri_id, (int)$uid); } DI::baseUrl()->redirect('events'); diff --git a/mod/item.php b/mod/item.php index d180cb08a..8c256cfab 100644 --- a/mod/item.php +++ b/mod/item.php @@ -781,7 +781,7 @@ function item_post(App $a) { // When we are doing some forum posting via ! we have to start the notifier manually. // These kind of posts don't initiate the notifier call in the item class. if ($only_to_forum) { - Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => false], "Notifier", Delivery::POST, $post_id); + Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => false], "Notifier", Delivery::POST, (int)$datarray['uri-id'], (int)$datarray['uid']); } Logger::info('post_complete'); diff --git a/mod/tagger.php b/mod/tagger.php index 38575a215..5e989c7cd 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -176,7 +176,9 @@ EOT; Hook::callAll('post_local_end', $arr); - Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $post_id); + $post = Post::selectFirst(['uri-id', 'uid'], ['id' => $post_id]); + + Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $post['uri-id'], $post['uid']); exit(); } diff --git a/src/Core/System.php b/src/Core/System.php index e84fcb573..38db75d89 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -53,6 +53,12 @@ class System while ($func = array_pop($trace)) { if (!empty($func['class'])) { + if (in_array($previous['function'], ['insert', 'fetch', 'toArray', 'exists', 'count', 'selectFirst', 'selectToArray', + 'select', 'update', 'delete', 'selectFirstForUser', 'selectForUser']) + && (substr($previous['class'], 0, 15) === 'Friendica\Model')) { + continue; + } + // Don't show multiple calls from the Database classes to show the essential parts of the callstack $func['database'] = in_array($func['class'], ['Friendica\Database\DBA', 'Friendica\Database\Database']); if (!$previous['database'] || !$func['database']) { diff --git a/src/Model/Event.php b/src/Model/Event.php index c5a8ef788..e6c609283 100644 --- a/src/Model/Event.php +++ b/src/Model/Event.php @@ -173,32 +173,32 @@ class Event { $ev = []; - $match = ''; + $match = []; if (preg_match("/\[event\-summary\](.*?)\[\/event\-summary\]/is", $text, $match)) { $ev['summary'] = $match[1]; } - $match = ''; + $match = []; if (preg_match("/\[event\-description\](.*?)\[\/event\-description\]/is", $text, $match)) { $ev['desc'] = $match[1]; } - $match = ''; + $match = []; if (preg_match("/\[event\-start\](.*?)\[\/event\-start\]/is", $text, $match)) { $ev['start'] = $match[1]; } - $match = ''; + $match = []; if (preg_match("/\[event\-finish\](.*?)\[\/event\-finish\]/is", $text, $match)) { $ev['finish'] = $match[1]; } - $match = ''; + $match = []; if (preg_match("/\[event\-location\](.*?)\[\/event\-location\]/is", $text, $match)) { $ev['location'] = $match[1]; } - $match = ''; + $match = []; if (preg_match("/\[event\-adjust\](.*?)\[\/event\-adjust\]/is", $text, $match)) { $ev['adjust'] = $match[1]; } @@ -330,7 +330,7 @@ class Event DBA::update('event', $updated_fields, ['id' => $event['id'], 'uid' => $event['uid']]); - $item = Post::selectFirst(['id'], ['event-id' => $event['id'], 'uid' => $event['uid']]); + $item = Post::selectFirst(['id', 'uri-id'], ['event-id' => $event['id'], 'uid' => $event['uid']]); if (DBA::isResult($item)) { $object = '' . XML::escape(Activity\ObjectType::EVENT) . '' . XML::escape($event['uri']) . ''; $object .= '' . XML::escape(self::getBBCode($event)) . ''; @@ -339,9 +339,9 @@ class Event $fields = ['body' => self::getBBCode($event), 'object' => $object, 'edited' => $event['edited']]; Item::update($fields, ['id' => $item['id']]); - $item_id = $item['id']; + $uriid = $item['uri-id']; } else { - $item_id = 0; + $uriid = 0; } Hook::callAll('event_updated', $event['id']); @@ -349,7 +349,7 @@ class Event // New event. Store it. DBA::insert('event', $event); - $item_id = 0; + $uriid = 0; // Don't create an item for birthday events if ($event['type'] == 'event') { @@ -360,6 +360,7 @@ class Event $item_arr['uid'] = $event['uid']; $item_arr['contact-id'] = $event['cid']; $item_arr['uri'] = $event['uri']; + $item_arr['uri-id'] = ItemURI::getIdByURI($event['uri']); $item_arr['guid'] = $event['guid']; $item_arr['plink'] = $arr['plink'] ?? ''; $item_arr['post-type'] = Item::PT_EVENT; @@ -392,13 +393,15 @@ class Event $item_arr['object'] .= '' . XML::escape(self::getBBCode($event)) . ''; $item_arr['object'] .= '' . "\n"; - $item_id = Item::insert($item_arr); + if (Item::insert($item_arr)) { + $uriid = $item_arr['uri-id']; + } } Hook::callAll("event_created", $event['id']); } - return $item_id; + return $uriid; } /** diff --git a/src/Model/Item.php b/src/Model/Item.php index 814696a49..28e0e25f4 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -212,7 +212,8 @@ class Item DBA::close($items); foreach ($notify_items as $notify_item) { - Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $notify_item); + $post = Post::selectFirst(['uri-id', 'uid'], ['id' => $notify_item]); + Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, (int)$post['uri-id'], (int)$post['uid']); } return $rows; @@ -354,7 +355,7 @@ class Item // send the notification upstream/downstream if ($priority) { - Worker::add(['priority' => $priority, 'dont_fork' => true], "Notifier", Delivery::DELETION, intval($item['id'])); + Worker::add(['priority' => $priority, 'dont_fork' => true], "Notifier", Delivery::DELETION, (int)$item['uri-id'], (int)$item['uid']); } } elseif ($item['uid'] != 0) { Post\User::update($item['uri-id'], $item['uid'], ['hidden' => true]); @@ -1142,7 +1143,7 @@ class Item } if ($transmit) { - Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', $notify_type, $current_post); + Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', $notify_type, (int)$item['uri-id'], (int)$item['uid']); } return $current_post; @@ -1866,7 +1867,7 @@ class Item 'owner-id' => $owner_id, 'private' => $private, 'psid' => $psid]; self::update($fields, ['id' => $item_id]); - Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', Delivery::POST, $item_id); + Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', Delivery::POST, (int)$item['uri-id'], (int)$item['uid']); self::performActivity($item_id, 'announce', $uid); diff --git a/src/Model/Post.php b/src/Model/Post.php index 4f06babf9..fe2171d29 100644 --- a/src/Model/Post.php +++ b/src/Model/Post.php @@ -246,13 +246,7 @@ class Post */ public static function select(array $selected = [], array $condition = [], $params = []) { - $timestamp = microtime(true); - $data = self::selectView('post-view', $selected, $condition, $params); - - $duration = microtime(true) - $timestamp;; - if ($duration > 0.1) - Logger::info('Blubb', ['duration' => $duration, 'selected' => $selected, 'condition' => $condition, 'params' => $params, 'callstack' => System::callstack(20)]); - return $data; + return self::selectView('post-view', $selected, $condition, $params); } /** @@ -335,7 +329,6 @@ class Post */ public static function selectForUser($uid, array $selected = [], array $condition = [], $params = []) { - //Logger::info('Blubb', ['uid' => $uid, 'selected' => $selected, 'condition' => $condition, 'params' => $params]); return self::selectViewForUser('post-view', $uid, $selected, $condition, $params); } diff --git a/src/Worker/APDelivery.php b/src/Worker/APDelivery.php index 9f0af133e..099fdc397 100644 --- a/src/Worker/APDelivery.php +++ b/src/Worker/APDelivery.php @@ -25,7 +25,6 @@ use Friendica\Core\Logger; use Friendica\Core\Worker; use Friendica\Model\Contact; use Friendica\Model\GServer; -use Friendica\Model\Item; use Friendica\Model\Post; use Friendica\Protocol\ActivityPub; use Friendica\Util\HTTPSignature; @@ -40,10 +39,11 @@ class APDelivery * @param string $inbox The URL of the recipient profile * @param integer $uid The ID of the user who triggered this delivery * @param array $receivers The contact IDs related to the inbox URL for contact archival housekeeping + * @param int $uri_id URI-ID of item to be transmitted * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ - public static function execute(string $cmd, int $item_id, string $inbox, int $uid, array $receivers = []) + public static function execute(string $cmd, int $item_id, string $inbox, int $uid, array $receivers = [], int $uri_id = 0) { if (ActivityPub\Transmitter::archivedInbox($inbox)) { Logger::info('Inbox is archived', ['cmd' => $cmd, 'inbox' => $inbox, 'id' => $item_id, 'uid' => $uid]); @@ -54,7 +54,19 @@ class APDelivery return; } - Logger::info('Invoked', ['cmd' => $cmd, 'inbox' => $inbox, 'id' => $item_id, 'uid' => $uid]); + if (empty($uri_id) && !empty($item_id)) { + $item = Post::selectFirst(['uri-id'], ['id' => $item_id]); + if (!empty($item['uri-id'])) { + $uri_id = $item['uri-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; @@ -81,8 +93,6 @@ class APDelivery } // This should never fail and is temporariy (until the move to the "post" structure) - $item = Post::selectFirst(['uri-id'], ['id' => $item_id]); - $uriid = $item['uri-id'] ?? 0; $gsid = null; foreach ($receivers as $receiver) { @@ -105,9 +115,9 @@ class APDelivery } if (!$success && !Worker::defer() && in_array($cmd, [Delivery::POST])) { - Post\DeliveryData::incrementQueueFailed($uriid); + Post\DeliveryData::incrementQueueFailed($uri_id); } elseif ($success && in_array($cmd, [Delivery::POST])) { - Post\DeliveryData::incrementQueueDone($uriid, Post\DeliveryData::ACTIVITYPUB); + Post\DeliveryData::incrementQueueDone($uri_id, Post\DeliveryData::ACTIVITYPUB); } } } diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index d5a3e8f5c..faba263e9 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -36,6 +36,7 @@ use Friendica\Core\Worker; use Friendica\Model\Conversation; use Friendica\Model\FContact; use Friendica\Model\Item; +use Friendica\Model\Post; use Friendica\Protocol\Relay; class Delivery @@ -50,9 +51,20 @@ class Delivery const REMOVAL = 'removeme'; const PROFILEUPDATE = 'profileupdate'; - public static function execute($cmd, $target_id, $contact_id) + public static function execute(string $cmd, int $post_uriid, int $contact_id, int $sender_uid = 0) { - Logger::info('Invoked', ['cmd' => $cmd, 'target' => $target_id, 'contact' => $contact_id]); + Logger::info('Invoked', ['cmd' => $cmd, 'target' => $post_uriid, 'sender_uid' => $sender_uid, 'contact' => $contact_id]); + + 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']; + } else { + $target_id = $post_uriid; + } $top_level = false; $followup = false; diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 312dcc0f9..836e4c680 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -53,11 +53,22 @@ use Friendica\Protocol\Salmon; class Notifier { - public static function execute(string $cmd, int $target_id) + public static function execute(string $cmd, int $post_uriid, int $sender_uid = 0) { $a = DI::app(); - Logger::info('Invoked', ['cmd' => $cmd, 'target' => $target_id]); + Logger::info('Invoked', ['cmd' => $cmd, 'target' => $post_uriid, 'sender_uid' => $sender_uid]); + + 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']; + } else { + $target_id = $post_uriid; + } $top_level = false; $recipients = []; @@ -85,7 +96,7 @@ class Notifier $ap_contacts = array_merge($ap_contacts, $receivers); Logger::info('Delivery via ActivityPub', ['cmd' => $cmd, 'target' => $target_id, 'inbox' => $inbox]); Worker::add(['priority' => PRIORITY_HIGH, 'created' => $a->queue['created'], 'dont_fork' => true], - 'APDelivery', $cmd, $target_id, $inbox, $uid, $receivers); + 'APDelivery', $cmd, $target_id, $inbox, $uid, $receivers, $post_uriid); } } elseif ($cmd == Delivery::SUGGESTION) { $suggest = DI::fsuggest()->getById($target_id); @@ -305,8 +316,8 @@ class Notifier /// @todo Possibly we should not uplink when the author is the forum itself? if ((intval($parent['forum_mode']) == 1) && !$top_level && ($cmd !== Delivery::UPLINK) - && ($target_item['verb'] != Activity::ANNOUNCE)) { - Worker::add($a->queue['priority'], 'Notifier', Delivery::UPLINK, $target_id); + && ($target_item['verb'] != Activity::ANNOUNCE)) { + Worker::add($a->queue['priority'], 'Notifier', Delivery::UPLINK, $post_uriid, $sender_uid); } foreach ($items as $item) { @@ -452,13 +463,13 @@ class Notifier $conversants = array_merge($contacts, $relay_list); - $delivery_queue_count += self::delivery($cmd, $target_id, $target_item, $thr_parent, $owner, $batch_delivery, true, $conversants, $ap_contacts, []); + $delivery_queue_count += self::delivery($cmd, $post_uriid, $sender_uid, $target_item, $thr_parent, $owner, $batch_delivery, true, $conversants, $ap_contacts, []); $push_notify = true; } $contacts = DBA::toArray($delivery_contacts_stmt); - $delivery_queue_count += self::delivery($cmd, $target_id, $target_item, $thr_parent, $owner, $batch_delivery, false, $contacts, $ap_contacts, $conversants); + $delivery_queue_count += self::delivery($cmd, $post_uriid, $sender_uid, $target_item, $thr_parent, $owner, $batch_delivery, false, $contacts, $ap_contacts, $conversants); $delivery_queue_count += self::deliverOStatus($target_id, $target_item, $owner, $url_recipients, $public_message, $push_notify); @@ -487,7 +498,8 @@ class Notifier * Deliver the message to the contacts * * @param string $cmd - * @param int $target_id + * @param int $post_uriid + * @param int $sender_uid * @param array $target_item * @param array $thr_parent * @param array $owner @@ -499,7 +511,7 @@ class Notifier * @throws InternalServerErrorException * @throws Exception */ - private static function delivery(string $cmd, int $target_id, array $target_item, array $thr_parent, array $owner, bool $batch_delivery, bool $in_batch, array $contacts, array $ap_contacts, array $conversants = []) + private static function delivery(string $cmd, int $post_uriid, int $sender_uid, array $target_item, array $thr_parent, array $owner, bool $batch_delivery, bool $in_batch, array $contacts, array $ap_contacts, array $conversants = []) { $a = DI::app(); $delivery_queue_count = 0; @@ -511,38 +523,38 @@ class Notifier } if (in_array($contact['id'], $ap_contacts)) { - Logger::info('Contact is already delivered via AP, so skip delivery via legacy DFRN/Diaspora', ['target' => $target_id, 'contact' => $contact['url']]); + Logger::info('Contact is already delivered via AP, so skip delivery via legacy DFRN/Diaspora', ['target' => $post_uriid, 'uid' => $sender_uid, 'contact' => $contact['url']]); continue; } if (!empty($contact['id']) && Contact::isArchived($contact['id'])) { - Logger::info('Contact is archived, so skip delivery', ['target' => $target_id, 'contact' => $contact['url']]); + Logger::info('Contact is archived, so skip delivery', ['target' => $post_uriid, 'uid' => $sender_uid, 'contact' => $contact['url']]); continue; } if (self::isRemovalActivity($cmd, $owner, $contact['network'])) { - Logger::info('Contact does no supports account removal commands, so skip delivery', ['target' => $target_id, 'contact' => $contact['url']]); + Logger::info('Contact does no supports account removal commands, so skip delivery', ['target' => $post_uriid, 'uid' => $sender_uid, 'contact' => $contact['url']]); continue; } if (self::skipActivityPubForDiaspora($contact, $target_item, $thr_parent)) { - Logger::info('Contact is from Diaspora, but the replied author is from ActivityPub, so skip delivery via Diaspora', ['id' => $target_id, 'url' => $contact['url']]); + Logger::info('Contact is from Diaspora, but the replied author is from ActivityPub, so skip delivery via Diaspora', ['id' => $post_uriid, 'uid' => $sender_uid, 'url' => $contact['url']]); continue; } // Don't deliver to Diaspora if it already had been done as batch delivery if (!$in_batch && $batch_delivery && ($contact['network'] == Protocol::DIASPORA)) { - Logger::info('Diaspora contact is already delivered via batch', ['id' => $target_id, 'contact' => $contact]); + Logger::info('Diaspora contact is already delivered via batch', ['id' => $post_uriid, 'uid' => $sender_uid, 'contact' => $contact]); continue; } // Don't deliver to folks who have already been delivered to if (in_array($contact['id'], $conversants)) { - Logger::info('Already delivery', ['id' => $target_id, 'contact' => $contact]); + Logger::info('Already delivery', ['id' => $post_uriid, 'uid' => $sender_uid, 'contact' => $contact]); continue; } - Logger::info('Delivery', ['batch' => $in_batch, 'target' => $target_id, 'guid' => $target_item['guid'] ?? '', 'to' => $contact]); + Logger::info('Delivery', ['batch' => $in_batch, 'target' => $post_uriid, 'uid' => $sender_uid, 'guid' => $target_item['guid'] ?? '', 'to' => $contact]); // Ensure that posts with our own protocol arrives before Diaspora posts arrive. // Situation is that sometimes Friendica servers receive Friendica posts over the Diaspora protocol first. @@ -554,7 +566,7 @@ class Notifier $deliver_options = ['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true]; } - if (Worker::add($deliver_options, 'Delivery', $cmd, $target_id, (int)$contact['id'])) { + if (Worker::add($deliver_options, 'Delivery', $cmd, $post_uriid, (int)$contact['id'], $sender_uid)) { $delivery_queue_count++; } } @@ -767,7 +779,7 @@ class Notifier Logger::info('Delivery via ActivityPub', ['cmd' => $cmd, 'id' => $target_item['id'], 'inbox' => $inbox]); if (Worker::add(['priority' => $priority, 'created' => $created, 'dont_fork' => true], - 'APDelivery', $cmd, $target_item['id'], $inbox, $uid, $receivers)) { + 'APDelivery', $cmd, $target_item['id'], $inbox, $uid, $receivers, $target_item['uri-id'])) { $delivery_queue_count++; } } @@ -776,7 +788,7 @@ class Notifier foreach ($relay_inboxes as $inbox) { Logger::info('Delivery to relay servers via ActivityPub', ['cmd' => $cmd, 'id' => $target_item['id'], 'inbox' => $inbox]); - if (Worker::add(['priority' => $priority, 'dont_fork' => true], 'APDelivery', $cmd, $target_item['id'], $inbox, $uid)) { + if (Worker::add(['priority' => $priority, 'dont_fork' => true], 'APDelivery', $cmd, $target_item['id'], $inbox, $uid, [], $target_item['uri-id'])) { $delivery_queue_count++; } } From 36357e790e460b438004be6320e5cea8634b0c21 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 14 Feb 2021 18:33:15 +0000 Subject: [PATCH 04/25] "id" is now post-user-id --- src/Database/DBStructure.php | 2 +- src/Database/PostUpdate.php | 7 +++- src/Model/Item.php | 78 ++++++++++++++++++------------------ src/Worker/APDelivery.php | 3 +- src/Worker/Delivery.php | 7 ++++ src/Worker/Expire.php | 6 +-- src/Worker/Notifier.php | 8 ++++ src/Worker/RemoveContact.php | 6 +-- static/dbview.config.php | 22 ++++------ 9 files changed, 76 insertions(+), 63 deletions(-) diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index 6ad6bb527..3aedc435f 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -1232,7 +1232,7 @@ class DBStructure } elseif ($verbose) { echo "Zero permissionset already added\n"; } - if (!self::existsForeignKeyForField('item', 'psid')) { + if (self::existsTable('item') && !self::existsForeignKeyForField('item', 'psid')) { $sets = DBA::p("SELECT `psid`, `item`.`uid`, `item`.`private` FROM `item` LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid` WHERE `permissionset`.`id` IS NULL AND NOT `psid` IS NULL"); diff --git a/src/Database/PostUpdate.php b/src/Database/PostUpdate.php index 3a1333780..a58281e48 100644 --- a/src/Database/PostUpdate.php +++ b/src/Database/PostUpdate.php @@ -179,6 +179,11 @@ class PostUpdate return true; } + if (!DBStructure::existsTable('item')) { + DI::config()->set('system', 'post_update_version', 1329); + return true; + } + $id = DI::config()->get('system', 'post_update_version_1329_id', 0); Logger::info('Start', ['item' => $id]); @@ -514,7 +519,7 @@ class PostUpdate return true; } - if (!DBStructure::existsTable('item-activity')) { + if (!DBStructure::existsTable('item-activity') || !DBStructure::existsTable('item')) { DI::config()->set('system', 'post_update_version', 1347); return true; } diff --git a/src/Model/Item.php b/src/Model/Item.php index 28e0e25f4..8d2eefe0a 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1031,14 +1031,14 @@ class Item return 0; } - $id = Post\User::insert($item['uri-id'], $item['uid'], $item); - if (!$id) { + $post_user_id = Post\User::insert($item['uri-id'], $item['uid'], $item); + if (!$post_user_id) { Logger::notice('Post-User is already inserted - aborting', ['uid' => $item['uid'], 'uri-id' => $item['uri-id']]); return 0; } if ($item['gravity'] == GRAVITY_PARENT) { - $item['post-user-id'] = $id; + $item['post-user-id'] = $post_user_id; Post\ThreadUser::insert($item['uri-id'], $item['uid'], $item); } @@ -1071,82 +1071,78 @@ class Item // Set parent id DBA::update('item', ['parent' => $parent_id], ['id' => $current_post]); - $item['id'] = $current_post; - $item['parent'] = $parent_id; + $posted_item = Post::selectFirst(self::ITEM_FIELDLIST, ['post-user-id' => $post_user_id]); + if (!DBA::isResult($posted_item)) { + Logger::warning('new item not found in DB', ['id' => $post_user_id]); + return 0; + } // update the commented timestamp on the parent if (DI::config()->get('system', 'like_no_comment')) { // Update when it is a comment - $update_commented = in_array($item['gravity'], [GRAVITY_PARENT, GRAVITY_COMMENT]); + $update_commented = in_array($posted_item['gravity'], [GRAVITY_PARENT, GRAVITY_COMMENT]); } else { // Update when it isn't a follow or tag verb - $update_commented = !in_array($item['verb'], [Activity::FOLLOW, Activity::TAG]); + $update_commented = !in_array($posted_item['verb'], [Activity::FOLLOW, Activity::TAG]); } if ($update_commented) { - Post::update(['commented' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()], ['id' => $parent_id]); + Post::update(['commented' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()], ['id' => $post_user_id]); } else { - Post::update(['changed' => DateTimeFormat::utcNow()], ['id' => $parent_id]); + Post::update(['changed' => DateTimeFormat::utcNow()], ['uri-id' => $posted_item['parent-uri-id'], 'uid' => $posted_item['uid']]); } // In that function we check if this is a forum post. Additionally we delete the item under certain circumstances - if (self::tagDeliver($item['uid'], $current_post)) { + if (self::tagDeliver($posted_item['uid'], $post_user_id)) { // Get the user information for the logging $user = User::getById($uid); - Logger::notice('Item had been deleted', ['id' => $current_post, 'user' => $uid, 'account-type' => $user['account-type']]); + Logger::notice('Item had been deleted', ['id' => $post_user_id, 'user' => $uid, 'account-type' => $user['account-type']]); return 0; } if (!$dontcache) { - $posted_item = Post::selectFirst(self::ITEM_FIELDLIST, ['id' => $current_post]); - if (DBA::isResult($posted_item)) { - if ($notify) { - Hook::callAll('post_local_end', $posted_item); - } else { - Hook::callAll('post_remote_end', $posted_item); - } + if ($notify) { + Hook::callAll('post_local_end', $posted_item); } else { - Logger::log('new item not found in DB, id ' . $current_post); - } + Hook::callAll('post_remote_end', $posted_item); + } } - if ($item['gravity'] === GRAVITY_PARENT) { - self::addShadow($current_post); + if ($posted_item['gravity'] === GRAVITY_PARENT) { + self::addShadow($post_user_id); } else { - self::addShadowPost($current_post); + self::addShadowPost($post_user_id); } - self::updateContact($item); + self::updateContact($posted_item); - Post\UserNotification::setNotification($item['uri-id'], $item['uid']); + Post\UserNotification::setNotification($posted_item['uri-id'], $posted_item['uid']); - check_user_notification($item['uri-id'], $item['uid']); - //check_user_notification($current_post); + check_user_notification($posted_item['uri-id'], $posted_item['uid']); // Distribute items to users who subscribed to their tags - self::distributeByTags($item); + self::distributeByTags($posted_item); // Automatically reshare the item if the "remote_self" option is selected - self::autoReshare($item); + self::autoReshare($posted_item); - $transmit = $notify || ($item['visible'] && ($parent_origin || $item['origin'])); + $transmit = $notify || ($posted_item['visible'] && ($parent_origin || $posted_item['origin'])); if ($transmit) { - $transmit_item = Post::selectFirst(['verb', 'origin'], ['id' => $item['id']]); // Don't relay participation messages - if (($transmit_item['verb'] == Activity::FOLLOW) && - (!$transmit_item['origin'] || ($item['author-id'] != Contact::getPublicIdByUserId($uid)))) { - Logger::info('Participation messages will not be relayed', ['item' => $item['id'], 'uri' => $item['uri'], 'verb' => $transmit_item['verb']]); + if (($posted_item['verb'] == Activity::FOLLOW) && + (!$posted_item['origin'] || ($posted_item['author-id'] != Contact::getPublicIdByUserId($uid)))) { + Logger::info('Participation messages will not be relayed', ['item' => $posted_item['id'], 'uri' => $posted_item['uri'], 'verb' => $posted_item['verb']]); $transmit = false; } } if ($transmit) { - Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', $notify_type, (int)$item['uri-id'], (int)$item['uid']); + Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', $notify_type, (int)$posted_item['uri-id'], (int)$posted_item['uid']); } - return $current_post; + return $post_user_id; } /** @@ -1235,6 +1231,7 @@ class Item $condition = ["`id` IN (SELECT `parent` FROM `post-view` WHERE `id` = ?)", $itemid]; $parent = Post::selectFirst(['owner-id'], $condition); if (!DBA::isResult($parent)) { + Logger::warning('Item not found', ['condition' => $condition]); return; } @@ -1244,6 +1241,7 @@ class Item 'visible' => true, 'deleted' => false, 'private' => [self::PUBLIC, self::UNLISTED]]; $item = Post::selectFirst(self::ITEM_FIELDLIST, $condition); if (!DBA::isResult($item)) { + Logger::warning('Item not found', ['condition' => $condition]); return; } @@ -1421,7 +1419,7 @@ class Item private static function addShadow($itemid) { $fields = ['uid', 'private', 'visible', 'deleted', 'network', 'uri-id']; - $condition = ['id' => $itemid, 'parent' => [0, $itemid]]; + $condition = ['id' => $itemid, 'gravity' => GRAVITY_PARENT]; $item = Post::selectFirst($fields, $condition); if (!DBA::isResult($item)) { @@ -1816,7 +1814,7 @@ class Item if (!$mention) { if (($community_page || $prvgroup) && !$item['wall'] && !$item['origin'] && ($item['gravity'] == GRAVITY_PARENT)) { - Logger::info('Delete private group/communiy top-level item without mention', ['id' => $item_id, 'guid'=> $item['guid']]); + Logger::info('Delete private group/communiy top-level item without mention', ['id' => $item['id'], 'guid'=> $item['guid']]); DBA::delete('item', ['uri-id' => $item['uri-id'], 'uid' => $item['uid']]); Post\User::delete(['uri-id' => $item['uri-id'], 'uid' => $item['uid']]); return true; @@ -1865,11 +1863,11 @@ class Item $fields = ['wall' => true, 'origin' => true, 'forum_mode' => $forum_mode, 'contact-id' => $self['id'], 'owner-id' => $owner_id, 'private' => $private, 'psid' => $psid]; - self::update($fields, ['id' => $item_id]); + self::update($fields, ['id' => $item['id']]); Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', Delivery::POST, (int)$item['uri-id'], (int)$item['uid']); - self::performActivity($item_id, 'announce', $uid); + self::performActivity($item['id'], 'announce', $uid); return false; } diff --git a/src/Worker/APDelivery.php b/src/Worker/APDelivery.php index 099fdc397..99ea6f832 100644 --- a/src/Worker/APDelivery.php +++ b/src/Worker/APDelivery.php @@ -55,9 +55,10 @@ class APDelivery } if (empty($uri_id) && !empty($item_id)) { - $item = Post::selectFirst(['uri-id'], ['id' => $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]); diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index faba263e9..e2db058ea 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -62,6 +62,13 @@ class Delivery 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']; + } } else { $target_id = $post_uriid; } diff --git a/src/Worker/Expire.php b/src/Worker/Expire.php index 31c0af039..ba984bb21 100644 --- a/src/Worker/Expire.php +++ b/src/Worker/Expire.php @@ -44,10 +44,10 @@ 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(['id', 'guid', 'uri-id', 'uid'], $condition); + $rows = Post::select(['item-id', 'guid', 'uri-id', 'uid'], $condition); while ($row = Post::fetch($rows)) { - Logger::info('Delete expired item', ['id' => $row['id'], 'guid' => $row['guid']]); - DBA::delete('item', ['id' => $row['id']]); + Logger::info('Delete expired item', ['id' => $row['item-id'], 'guid' => $row['guid']]); + DBA::delete('item', ['id' => $row['item-id']]); Post\User::delete(['uri-id' => $row['uri-id'], 'uid' => $row['uid']]); Post\ThreadUser::delete(['uri-id' => $row['uri-id'], 'uid' => $row['uid']]); } diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 836e4c680..f225adf11 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -66,6 +66,14 @@ class Notifier return; } $target_id = $post['id']; + } elseif (!in_array($cmd, [Delivery::MAIL, Delivery::SUGGESTION, Delivery::REMOVAL, Delivery::RELOCATION])) { + $post = Post::selectFirst(['id'], ['item-id' => $post_uriid]); + $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']; + } } else { $target_id = $post_uriid; } diff --git a/src/Worker/RemoveContact.php b/src/Worker/RemoveContact.php index 6d48dd956..f038cc5e8 100644 --- a/src/Worker/RemoveContact.php +++ b/src/Worker/RemoveContact.php @@ -47,10 +47,10 @@ class RemoveContact { $condition = ['uid' => $contact['uid'], 'contact-id' => $id]; } do { - $items = Post::select(['id', 'post-user-id', 'uri-id', 'guid'], $condition, ['limit' => 100]); + $items = Post::select(['item-id', 'post-user-id', 'uri-id', 'guid'], $condition, ['limit' => 100]); while ($item = Post::fetch($items)) { - Logger::info('Delete removed contact item', ['id' => $item['id'], 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]); - DBA::delete('item', ['id' => $item['id']]); + 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']]); Post::delete(['uri-id' => $item['uri-id']]); Post\ThreadUser::delete(['post-user-id' => $item['post-user-id']]); Post\Thread::delete(['uri-id' => $item['uri-id']]); diff --git a/static/dbview.config.php b/static/dbview.config.php index eba31db6a..79a2407f4 100644 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -39,12 +39,11 @@ return [ "post-view" => [ "fields" => [ - "id" => ["item", "id"], + "id" => ["post-user", "id"], "item-id" => ["item", "id"], "post-user-id" => ["post-user", "id"], "uid" => ["post-user", "uid"], - "parent" => ["item", "parent"], - "parent-user-id" => ["parent-post", "id"], + "parent" => ["parent-post", "id"], "uri" => ["item-uri", "uri"], "uri-id" => ["post-user", "uri-id"], "parent-uri" => ["parent-item-uri", "uri"], @@ -196,13 +195,12 @@ ], "post-thread-view" => [ "fields" => [ - "id" => ["item", "id"], + "id" => ["post-user", "id"], "item-id" => ["item", "id"], - "iid" => ["item", "id"], + "iid" => ["post-user", "id"], "post-user-id" => ["post-user", "id"], "uid" => ["post-thread-user", "uid"], - "parent" => ["item", "parent"], - "parent-user-id" => ["parent-post", "id"], + "parent" => ["parent-post", "id"], "uri" => ["item-uri", "uri"], "uri-id" => ["post-thread-user", "uri-id"], "parent-uri" => ["parent-item-uri", "uri"], @@ -381,8 +379,7 @@ "network-item-view" => [ "fields" => [ "uri-id" => ["post-user", "uri-id"], - "parent" => ["item", "parent"], - "parent-uri-id" => ["post-user", "parent-uri-id"], + "parent" => ["post-user", "parent-uri-id"], "received" => ["post-user", "received"], "commented" => ["post-thread-user", "commented"], "created" => ["post-user", "created"], @@ -396,8 +393,7 @@ "contact-type" => ["ownercontact", "contact-type"], ], "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` + STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid` INNER JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id` LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id` LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id` @@ -411,8 +407,7 @@ "network-thread-view" => [ "fields" => [ "uri-id" => ["post-thread-user", "uri-id"], - "parent-uri-id" => ["post-user", "parent-uri-id"], - "parent" => ["item", "id"], + "parent" => ["post-user", "parent-uri-id"], "received" => ["post-thread-user", "received"], "commented" => ["post-thread-user", "commented"], "created" => ["post-thread-user", "created"], @@ -425,7 +420,6 @@ ], "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` STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id` LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id` LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id` From e1c79a41d90fd092d3eea0b8763834e74499697b Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 14 Feb 2021 20:27:31 +0000 Subject: [PATCH 05/25] We now don't store in the "item" table anymore --- src/Model/Item.php | 40 +- src/Model/Post.php | 18 - src/Worker/Expire.php | 5 +- src/Worker/ExpireAndRemoveUsers.php | 5 +- src/Worker/RemoveContact.php | 5 +- tests/datasets/api.fixture.php | 686 ++++++++++------------------ update.php | 13 +- 7 files changed, 275 insertions(+), 497 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 8d2eefe0a..397ea0b31 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1042,38 +1042,13 @@ class Item Post\ThreadUser::insert($item['uri-id'], $item['uid'], $item); } - // Remove all fields that aren't part of the item table - $table_fields = DBStructure::getFieldsForTable('item', $item); - - // We remove all legacy fields that now are stored in other tables - foreach (self::LEGACY_FIELDLIST as $field) { - unset($table_fields[$field]); - } - - $result = DBA::insert('item', $table_fields); - - // When the item was successfully stored we fetch the ID of the item. - $current_post = DBA::lastInsertId(); - - if (empty($current_post) || !DBA::isResult($result)) { - // On failure store the data into a spool file so that the "SpoolPost" worker can try again later. - Logger::warning('Could not store item. it will be spooled', ['result' => $result, 'id' => $current_post]); - self::spool($orig_item); - return 0; - } - - Logger::notice('created item', ['id' => $current_post, 'uid' => $item['uid'], 'network' => $item['network'], 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]); - - if (!$parent_id || ($item['gravity'] === GRAVITY_PARENT)) { - $parent_id = $current_post; - } - - // Set parent id - DBA::update('item', ['parent' => $parent_id], ['id' => $current_post]); + Logger::notice('created item', ['post-id' => $post_user_id, 'uid' => $item['uid'], 'network' => $item['network'], 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]); $posted_item = Post::selectFirst(self::ITEM_FIELDLIST, ['post-user-id' => $post_user_id]); if (!DBA::isResult($posted_item)) { - Logger::warning('new item not found in DB', ['id' => $post_user_id]); + // On failure store the data into a spool file so that the "SpoolPost" worker can try again later. + Logger::warning('Could not store item. it will be spooled', ['id' => $post_user_id]); + self::spool($orig_item); return 0; } @@ -1164,15 +1139,15 @@ class Item return; } - $author = Contact::selectFirst(['url', 'contact-type'], ['id' => $item['author-id']]); + $author = Contact::selectFirst(['url', 'contact-type', 'network'], ['id' => $item['author-id']]); if (!DBA::isResult($author)) { Logger::error('Author not found', ['id' => $item['author-id']]); return; } $cid = Contact::getIdForURL($author['url'], $item['uid']); - if (empty($cid) || !Contact::isSharing($cid, $item['uid'])) { - Logger::info('The resharer is not a following contact: quit', ['resharer' => $author['url'], 'uid' => $item['uid']]); + if (empty($cid) || (!Contact::isSharing($cid, $item['uid'] && in_array($author['network'], Protocol::FEDERATED)))) { + Logger::info('The resharer is not a following contact: quit', ['resharer' => $author['url'], 'uid' => $item['uid'], 'cid' => $cid]); return; } @@ -1815,7 +1790,6 @@ class Item if (($community_page || $prvgroup) && !$item['wall'] && !$item['origin'] && ($item['gravity'] == GRAVITY_PARENT)) { Logger::info('Delete private group/communiy top-level item without mention', ['id' => $item['id'], 'guid'=> $item['guid']]); - DBA::delete('item', ['uri-id' => $item['uri-id'], 'uid' => $item['uid']]); Post\User::delete(['uri-id' => $item['uri-id'], 'uid' => $item['uid']]); return true; } diff --git a/src/Model/Post.php b/src/Model/Post.php index fe2171d29..ff86dc6f2 100644 --- a/src/Model/Post.php +++ b/src/Model/Post.php @@ -23,7 +23,6 @@ namespace Friendica\Model; use BadMethodCallException; use Friendica\Core\Logger; -use Friendica\Core\System; use Friendica\Database\Database; use Friendica\Database\DBA; use Friendica\Database\DBStructure; @@ -516,23 +515,6 @@ class Post $affected = max($affected, DBA::affectedRows()); } - $update_fields = []; - foreach (Item::USED_FIELDLIST as $field) { - if (array_key_exists($field, $fields)) { - $update_fields[$field] = $fields[$field]; - } - } - if (!empty($update_fields)) { - $rows = DBA::selectToArray('post-view', ['item-id'], $condition, []); - $ids = array_column($rows, 'item-id'); - if (!DBA::update('item', $update_fields, ['id' => $ids])) { - DBA::rollback(); - Logger::notice('Updating item failed', ['fields' => $update_fields, 'condition' => $condition]); - return false; - } - $affected = max($affected, DBA::affectedRows()); - } - DBA::commit(); Logger::info('Updated posts', ['rows' => $affected]); diff --git a/src/Worker/Expire.php b/src/Worker/Expire.php index ba984bb21..37357fc1f 100644 --- a/src/Worker/Expire.php +++ b/src/Worker/Expire.php @@ -25,6 +25,7 @@ use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\Database\DBStructure; use Friendica\DI; use Friendica\Model\Item; use Friendica\Model\Post; @@ -47,7 +48,9 @@ class Expire $rows = Post::select(['item-id', 'guid', 'uri-id', 'uid'], $condition); while ($row = Post::fetch($rows)) { Logger::info('Delete expired item', ['id' => $row['item-id'], 'guid' => $row['guid']]); - DBA::delete('item', ['id' => $row['item-id']]); + if (DBStructure::existsTable('item')) { + DBA::delete('item', ['id' => $row['item-id']]); + } Post\User::delete(['uri-id' => $row['uri-id'], 'uid' => $row['uid']]); Post\ThreadUser::delete(['uri-id' => $row['uri-id'], 'uid' => $row['uid']]); } diff --git a/src/Worker/ExpireAndRemoveUsers.php b/src/Worker/ExpireAndRemoveUsers.php index 8caaf131e..5052fa688 100644 --- a/src/Worker/ExpireAndRemoveUsers.php +++ b/src/Worker/ExpireAndRemoveUsers.php @@ -22,6 +22,7 @@ namespace Friendica\Worker; use Friendica\Database\DBA; +use Friendica\Database\DBStructure; use Friendica\Model\Photo; use Friendica\Model\User; @@ -64,7 +65,9 @@ class ExpireAndRemoveUsers // It seems that sometimes the system wants to delete the records in the wrong order. // So when the permissionset is deleted and these tables are still filled then an error is thrown. // So we now delete them before all other user related entries are deleted. - DBA::delete('item', ['uid' => $user['uid']]); + if (DBStructure::existsTable('item')) { + DBA::delete('item', ['uid' => $user['uid']]); + } DBA::delete('post-user', ['uid' => $user['uid']]); DBA::delete('profile_field', ['uid' => $user['uid']]); diff --git a/src/Worker/RemoveContact.php b/src/Worker/RemoveContact.php index f038cc5e8..d07780edf 100644 --- a/src/Worker/RemoveContact.php +++ b/src/Worker/RemoveContact.php @@ -23,6 +23,7 @@ namespace Friendica\Worker; use Friendica\Core\Logger; use Friendica\Database\DBA; +use Friendica\Database\DBStructure; use Friendica\Model\Photo; use Friendica\Model\Post; @@ -50,7 +51,9 @@ class RemoveContact { $items = Post::select(['item-id', 'post-user-id', 'uri-id', 'guid'], $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']]); + if (DBStructure::existsTable('item')) { + DBA::delete('item', ['id' => $item['item-id']]); + } Post::delete(['uri-id' => $item['uri-id']]); Post\ThreadUser::delete(['post-user-id' => $item['post-user-id']]); Post\Thread::delete(['uri-id' => $item['uri-id']]); diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index 4f85fe0ce..80756edbc 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -215,165 +215,6 @@ return [ 'plink' => 'http://localhost/display/6', ], ], - 'post-thread' => [ - [ - 'uri-id' => 1, - 'author-id' => 42, - 'owner-id' => 42, - 'causer-id' => 42, - 'network' => Protocol::DFRN, - ], - [ - 'uri-id' => 3, - 'author-id' => 43, - 'owner-id' => 43, - 'causer-id' => 43, - 'network' => Protocol::DFRN, - ], - [ - 'uri-id' => 6, - 'author-id' => 44, - 'owner-id' => 44, - 'causer-id' => 44, - 'network' => Protocol::DFRN, - ], - ], - 'post-user' => [ - [ - 'id' => 1, - 'uri-id' => 1, - 'uid' => 42, - 'contact-id' => 42, - 'unseen' => 1, - 'origin' => 1, - ], - [ - 'id' => 2, - 'uri-id' => 2, - 'uid' => 42, - 'contact-id' => 42, - 'unseen' => 0, - 'origin' => 1, - ], - [ - 'id' => 3, - 'uri-id' => 3, - 'uid' => 42, - 'contact-id' => 43, - 'unseen' => 0, - 'origin' => 1, - ], - [ - 'id' => 4, - 'uri-id' => 4, - 'uid' => 42, - 'contact-id' => 44, - 'unseen' => 0, - 'origin' => 1, - ], - [ - 'id' => 5, - 'uri-id' => 5, - 'uid' => 42, - 'contact-id' => 42, - 'unseen' => 0, - 'origin' => 1, - ], - [ - 'id' => 6, - 'uri-id' => 6, - 'uid' => 42, - 'contact-id' => 44, - 'unseen' => 0, - 'origin' => 1, - ], - [ - 'id' => 7, - 'uri-id' => 1, - 'uid' => 0, - 'contact-id' => 42, - 'unseen' => 1, - 'origin' => 0, - ], - [ - 'id' => 8, - 'uri-id' => 2, - 'uid' => 0, - 'contact-id' => 42, - 'unseen' => 0, - 'origin' => 0, - ], - [ - 'id' => 9, - 'uri-id' => 3, - 'uid' => 0, - 'contact-id' => 43, - 'unseen' => 0, - 'origin' => 0, - ], - [ - 'id' => 10, - 'uri-id' => 4, - 'uid' => 0, - 'contact-id' => 44, - 'unseen' => 0, - 'origin' => 0, - ], - [ - 'id' => 11, - 'uri-id' => 5, - 'uid' => 0, - 'contact-id' => 42, - 'unseen' => 0, - 'origin' => 0, - ], - [ - 'id' => 12, - 'uri-id' => 6, - 'uid' => 0, - 'contact-id' => 44, - 'unseen' => 0, - 'origin' => 0, - ], - ], - 'post-thread-user' => [ - [ - 'uri-id' => 1, - 'uid' => 42, - 'wall' => 1, - 'post-user-id' => 1, - ], - [ - 'uri-id' => 3, - 'uid' => 42, - 'wall' => 1, - 'post-user-id' => 3, - ], - [ - 'uri-id' => 6, - 'uid' => 42, - 'wall' => 1, - 'post-user-id' => 6, - ], - [ - 'uri-id' => 1, - 'uid' => 0, - 'wall' => 0, - 'post-user-id' => 7, - ], - [ - 'uri-id' => 3, - 'uid' => 0, - 'wall' => 0, - 'post-user-id' => 9, - ], - [ - 'uri-id' => 6, - 'uid' => 0, - 'wall' => 0, - 'post-user-id' => 12, - ], - ], 'post' => [ [ 'uri-id' => 1, @@ -454,326 +295,307 @@ return [ 'visible' => 1, ], ], - 'item' => [ + 'post-user' => [ [ - 'id' => 1, - 'uri-id' => 1, - 'uri' => '1', - 'visible' => 1, - 'contact-id' => 42, - 'author-id' => 42, - 'owner-id' => 42, - 'causer-id' => 42, - 'uid' => 42, - 'verb' => 'http://activitystrea.ms/schema/1.0/post', - 'unseen' => 1, - 'parent' => 1, + 'id' => 1, + 'uri-id' => 1, + 'uid' => 42, + 'contact-id' => 42, + 'unseen' => 1, + 'origin' => 1, 'parent-uri-id' => 1, - 'parent-uri' => '1', 'thr-parent-id' => 1, - 'thr-parent' => '1', - 'private' => Item::PUBLIC, - 'gravity' => GRAVITY_PARENT, - 'author-link' => 'http://localhost/profile/selfcontact', - 'wall' => 1, - 'starred' => 1, - 'origin' => 1, - 'allow_cid' => '', - 'allow_gid' => '', - 'deny_cid' => '', - 'deny_gid' => '', - 'guid' => '1', + 'gravity' => GRAVITY_PARENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 42, + 'causer-id' => 42, + 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'private' => Item::PUBLIC, + 'visible' => 1, ], [ - 'id' => 2, - 'uri-id' => 2, - 'uri' => '2', - 'visible' => 1, - 'contact-id' => 42, - 'author-id' => 42, - 'owner-id' => 42, - 'causer-id' => 42, - 'uid' => 42, - 'verb' => 'http://activitystrea.ms/schema/1.0/post', - 'unseen' => 0, - 'parent' => 1, + 'id' => 2, + 'uri-id' => 2, + 'uid' => 42, + 'contact-id' => 42, + 'unseen' => 0, + 'origin' => 1, 'parent-uri-id' => 1, - 'parent-uri' => '1', 'thr-parent-id' => 1, - 'thr-parent' => '1', - 'private' => Item::PUBLIC, - 'gravity' => GRAVITY_COMMENT, - 'author-link' => 'http://localhost/profile/selfcontact', - 'wall' => 1, - 'starred' => 0, - 'origin' => 1, - 'guid' => '2', + 'gravity' => GRAVITY_COMMENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 42, + 'causer-id' => 42, + 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'private' => Item::PUBLIC, + 'visible' => 1, ], [ - 'id' => 3, - 'uri-id' => 3, - 'uri' => '3', - 'visible' => 1, - 'contact-id' => 43, - 'author-id' => 43, - 'owner-id' => 42, - 'causer-id' => 43, - 'uid' => 42, - 'verb' => 'http://activitystrea.ms/schema/1.0/post', - 'unseen' => 0, - 'parent' => 3, + 'id' => 3, + 'uri-id' => 3, + 'uid' => 42, + 'contact-id' => 43, + 'unseen' => 0, + 'origin' => 1, 'parent-uri-id' => 3, - 'parent-uri' => '3', 'thr-parent-id' => 3, - 'thr-parent' => '3', - 'private' => Item::PUBLIC, - 'gravity' => GRAVITY_PARENT, - 'author-link' => 'http://localhost/profile/othercontact', - 'wall' => 1, - 'starred' => 0, - 'origin' => 1, - 'guid' => '3', + 'gravity' => GRAVITY_PARENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 43, + 'causer-id' => 43, + 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'private' => Item::PUBLIC, + 'visible' => 1, ], [ - 'id' => 4, - 'uri-id' => 4, - 'uri' => '4', - 'visible' => 1, - 'contact-id' => 44, - 'author-id' => 44, - 'owner-id' => 42, - 'causer-id' => 44, - 'uid' => 42, - 'verb' => 'http://activitystrea.ms/schema/1.0/post', - 'unseen' => 0, - 'body' => 'Friend user reply', - 'parent' => 1, + 'id' => 4, + 'uri-id' => 4, + 'uid' => 42, + 'contact-id' => 44, + 'unseen' => 0, + 'origin' => 1, 'parent-uri-id' => 1, - 'parent-uri' => '1', 'thr-parent-id' => 1, - 'thr-parent' => '1', - 'private' => Item::PUBLIC, - 'gravity' => GRAVITY_COMMENT, - 'author-link' => 'http://localhost/profile/othercontact', - 'wall' => 1, - 'starred' => 0, - 'origin' => 1, - 'guid' => '4', + 'gravity' => GRAVITY_COMMENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 44, + 'causer-id' => 44, + 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'private' => Item::PUBLIC, + 'visible' => 1, ], [ - - 'id' => 5, - 'uri-id' => 5, - 'uri' => '5', - 'visible' => 1, - 'contact-id' => 42, - 'author-id' => 42, - 'owner-id' => 42, - 'causer-id' => 42, - 'uid' => 42, - 'verb' => 'http://activitystrea.ms/schema/1.0/post', - 'unseen' => 0, - 'parent' => 1, + 'id' => 5, + 'uri-id' => 5, + 'uid' => 42, + 'contact-id' => 42, + 'unseen' => 0, + 'origin' => 1, 'parent-uri-id' => 1, - 'parent-uri' => '1', 'thr-parent-id' => 1, - 'thr-parent' => '1', - 'private' => Item::PUBLIC, - 'gravity' => GRAVITY_COMMENT, - 'author-link' => 'http://localhost/profile/othercontact', - 'wall' => 1, - 'starred' => 0, - 'origin' => 1, - 'allow_cid' => '', - 'allow_gid' => '', - 'deny_cid' => '', - 'deny_gid' => '', - 'guid' => '5', + 'gravity' => GRAVITY_COMMENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 42, + 'causer-id' => 42, + 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'private' => Item::PUBLIC, + 'visible' => 1, ], [ - 'id' => 6, - 'uri-id' => 6, - 'uri' => '6', - 'visible' => 1, - 'contact-id' => 44, - 'author-id' => 44, - 'owner-id' => 42, - 'causer-id' => 44, - 'uid' => 42, - 'verb' => 'http://activitystrea.ms/schema/1.0/post', - 'unseen' => 0, - 'parent' => 6, + 'id' => 6, + 'uri-id' => 6, + 'uid' => 42, + 'contact-id' => 44, + 'unseen' => 0, + 'origin' => 1, 'parent-uri-id' => 6, - 'parent-uri' => '6', 'thr-parent-id' => 6, - 'thr-parent' => '6', - 'private' => Item::PUBLIC, - 'gravity' => GRAVITY_PARENT, - 'author-link' => 'http://localhost/profile/othercontact', - 'wall' => 1, - 'starred' => 0, - 'origin' => 1, - 'guid' => '6', + 'gravity' => GRAVITY_PARENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 44, + 'causer-id' => 44, + 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'private' => Item::PUBLIC, + 'visible' => 1, ], [ - 'id' => 7, - 'uri-id' => 1, - 'uri' => '1', - 'visible' => 1, - 'contact-id' => 42, - 'author-id' => 42, - 'owner-id' => 42, - 'causer-id' => 42, - 'uid' => 0, - 'verb' => 'http://activitystrea.ms/schema/1.0/post', - 'unseen' => 1, - 'parent' => 7, + 'id' => 7, + 'uri-id' => 1, + 'uid' => 0, + 'contact-id' => 42, + 'unseen' => 1, + 'origin' => 0, 'parent-uri-id' => 1, - 'parent-uri' => '1', 'thr-parent-id' => 1, - 'thr-parent' => '1', - 'private' => Item::PUBLIC, - 'gravity' => GRAVITY_PARENT, - 'author-link' => 'http://localhost/profile/selfcontact', - 'wall' => 0, - 'starred' => 1, - 'origin' => 0, - 'allow_cid' => '', - 'allow_gid' => '', - 'deny_cid' => '', - 'deny_gid' => '', - 'guid' => '1', + 'gravity' => GRAVITY_PARENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 42, + 'causer-id' => 42, + 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'private' => Item::PUBLIC, + 'visible' => 1, ], [ - 'id' => 8, - 'uri-id' => 2, - 'uri' => '2', - 'visible' => 1, - 'contact-id' => 42, - 'author-id' => 42, - 'owner-id' => 42, - 'causer-id' => 42, - 'uid' => 0, - 'verb' => 'http://activitystrea.ms/schema/1.0/post', - 'unseen' => 0, - 'parent' => 7, + 'id' => 8, + 'uri-id' => 2, + 'uid' => 0, + 'contact-id' => 42, + 'unseen' => 0, + 'origin' => 0, 'parent-uri-id' => 1, - 'parent-uri' => '1', 'thr-parent-id' => 1, - 'thr-parent' => '1', - 'private' => Item::PUBLIC, - 'gravity' => GRAVITY_COMMENT, - 'author-link' => 'http://localhost/profile/selfcontact', - 'wall' => 0, - 'starred' => 0, - 'origin' => 0, - 'guid' => '2', + 'gravity' => GRAVITY_COMMENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 42, + 'causer-id' => 42, + 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'private' => Item::PUBLIC, + 'visible' => 1, ], [ - 'id' => 9, - 'uri-id' => 3, - 'uri' => '3', - 'visible' => 1, - 'contact-id' => 43, - 'author-id' => 43, - 'owner-id' => 42, - 'causer-id' => 43, - 'uid' => 0, - 'verb' => 'http://activitystrea.ms/schema/1.0/post', - 'unseen' => 0, - 'parent' => 9, + 'id' => 9, + 'uri-id' => 3, + 'uid' => 0, + 'contact-id' => 43, + 'unseen' => 0, + 'origin' => 0, 'parent-uri-id' => 3, - 'parent-uri' => '3', 'thr-parent-id' => 3, - 'thr-parent' => '3', - 'private' => Item::PUBLIC, - 'gravity' => GRAVITY_PARENT, - 'author-link' => 'http://localhost/profile/othercontact', - 'wall' => 0, - 'starred' => 0, - 'origin' => 0, - 'guid' => '3', + 'gravity' => GRAVITY_PARENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 43, + 'causer-id' => 43, + 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'private' => Item::PUBLIC, + 'visible' => 1, ], [ - 'id' => 10, - 'uri-id' => 4, - 'uri' => '4', - 'visible' => 1, - 'contact-id' => 44, - 'author-id' => 44, - 'owner-id' => 42, - 'causer-id' => 44, - 'uid' => 0, - 'verb' => 'http://activitystrea.ms/schema/1.0/post', - 'unseen' => 0, - 'body' => 'Friend user reply', - 'parent' => 7, + 'id' => 10, + 'uri-id' => 4, + 'uid' => 0, + 'contact-id' => 44, + 'unseen' => 0, + 'origin' => 0, 'parent-uri-id' => 1, - 'parent-uri' => '1', 'thr-parent-id' => 1, - 'thr-parent' => '1', - 'private' => Item::PUBLIC, - 'gravity' => GRAVITY_COMMENT, - 'author-link' => 'http://localhost/profile/othercontact', - 'wall' => 0, - 'starred' => 0, - 'origin' => 0, - 'guid' => '4', + 'gravity' => GRAVITY_COMMENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 44, + 'causer-id' => 44, + 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'private' => Item::PUBLIC, + 'visible' => 1, ], [ - - 'id' => 11, - 'uri-id' => 5, - 'uri' => '5', - 'visible' => 1, - 'contact-id' => 42, - 'author-id' => 42, - 'owner-id' => 42, - 'causer-id' => 42, - 'uid' => 0, - 'verb' => 'http://activitystrea.ms/schema/1.0/post', - 'unseen' => 0, - 'parent' => 7, + 'id' => 11, + 'uri-id' => 5, + 'uid' => 0, + 'contact-id' => 42, + 'unseen' => 0, + 'origin' => 0, 'parent-uri-id' => 1, - 'parent-uri' => '1', 'thr-parent-id' => 1, - 'thr-parent' => '1', - 'private' => Item::PUBLIC, - 'gravity' => GRAVITY_COMMENT, - 'author-link' => 'http://localhost/profile/othercontact', - 'wall' => 0, - 'starred' => 0, - 'origin' => 1, - 'allow_cid' => '', - 'allow_gid' => '', - 'deny_cid' => '', - 'deny_gid' => '', - 'guid' => '5', + 'gravity' => GRAVITY_COMMENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 42, + 'causer-id' => 42, + 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'private' => Item::PUBLIC, + 'visible' => 1, ], [ - 'id' => 12, - 'uri-id' => 6, - 'uri' => '6', - 'visible' => 1, - 'contact-id' => 44, - 'author-id' => 44, - 'owner-id' => 42, - 'causer-id' => 44, - 'uid' => 0, - 'verb' => 'http://activitystrea.ms/schema/1.0/post', - 'unseen' => 0, - 'parent' => 12, + 'id' => 12, + 'uri-id' => 6, + 'uid' => 0, + 'contact-id' => 44, + 'unseen' => 0, + 'origin' => 0, 'parent-uri-id' => 6, - 'parent-uri' => '6', 'thr-parent-id' => 6, - 'thr-parent' => '6', - 'private' => Item::PUBLIC, - 'gravity' => GRAVITY_PARENT, - 'author-link' => 'http://localhost/profile/othercontact', - 'wall' => 0, - 'starred' => 0, - 'origin' => 0, - 'guid' => '6', + 'gravity' => GRAVITY_PARENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 44, + 'causer-id' => 44, + 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'private' => Item::PUBLIC, + 'visible' => 1, + ], + ], + 'post-thread' => [ + [ + 'uri-id' => 1, + 'author-id' => 42, + 'owner-id' => 42, + 'causer-id' => 42, + 'network' => Protocol::DFRN, + ], + [ + 'uri-id' => 3, + 'author-id' => 43, + 'owner-id' => 43, + 'causer-id' => 43, + 'network' => Protocol::DFRN, + ], + [ + 'uri-id' => 6, + 'author-id' => 44, + 'owner-id' => 44, + 'causer-id' => 44, + 'network' => Protocol::DFRN, + ], + ], + 'post-thread-user' => [ + [ + 'uri-id' => 1, + 'uid' => 42, + 'wall' => 1, + 'post-user-id' => 1, + 'author-id' => 42, + 'owner-id' => 42, + 'causer-id' => 42, + 'network' => Protocol::DFRN, + ], + [ + 'uri-id' => 3, + 'uid' => 42, + 'wall' => 1, + 'post-user-id' => 3, + 'author-id' => 43, + 'owner-id' => 43, + 'causer-id' => 43, + 'network' => Protocol::DFRN, + ], + [ + 'uri-id' => 6, + 'uid' => 42, + 'wall' => 1, + 'post-user-id' => 6, + 'author-id' => 44, + 'owner-id' => 44, + 'causer-id' => 44, + 'network' => Protocol::DFRN, + ], + [ + 'uri-id' => 1, + 'uid' => 0, + 'wall' => 0, + 'post-user-id' => 7, + 'author-id' => 42, + 'owner-id' => 42, + 'causer-id' => 42, + 'network' => Protocol::DFRN, + ], + [ + 'uri-id' => 3, + 'uid' => 0, + 'wall' => 0, + 'post-user-id' => 9, + 'author-id' => 43, + 'owner-id' => 43, + 'causer-id' => 43, + 'network' => Protocol::DFRN, + ], + [ + 'uri-id' => 6, + 'uid' => 0, + 'wall' => 0, + 'post-user-id' => 12, + 'author-id' => 44, + 'owner-id' => 44, + 'causer-id' => 44, + 'network' => Protocol::DFRN, ], ], 'notify' => [ diff --git a/update.php b/update.php index 444189cc6..a59f0ca13 100644 --- a/update.php +++ b/update.php @@ -773,19 +773,13 @@ function update_1399() function update_1400() { -/* if (!DBA::e("INSERT IGNORE INTO `post` (`uri-id`, `parent-uri-id`, `thr-parent-id`, `owner-id`, `author-id`, `network`, - `created`, `received`, `edited`, `gravity`, `causer-id`, `post-type`, `vid`, `private`, `visible`, `deleted`) + `created`, `received`, `edited`, `gravity`, `causer-id`, `post-type`, `vid`, `private`, `visible`, `deleted`, `global`) SELECT `uri-id`, `parent-uri-id`, `thr-parent-id`, `owner-id`, `author-id`, `network`, `created`, `received`, `edited`, - `gravity`, `causer-id`, `post-type`, `vid`, `private`, `visible`, `deleted` FROM `item`")) { + `gravity`, `causer-id`, `post-type`, `vid`, `private`, `visible`, `deleted`, `global` FROM `item`")) { return Update::FAILED; } - if (!DBA::e("UPDATE `post` INNER JOIN `item` ON `item`.`uri-id` = `post`.`uri-id` AND `item`.`uid` = 0 - SET `post`.`global` = true")) { - return Update::FAILED; - -// -------------------------------------- if (!DBA::e("UPDATE `post-user` INNER JOIN `item` ON `item`.`uri-id` = `post-user`.`uri-id` AND `item`.`uid` = `post-user`.`uid` INNER JOIN `event` ON `item`.`event-id` = `event`.`id` AND `event`.`id` != 0 SET `post-user`.`event-id` = `item`.`event-id`")) { @@ -805,8 +799,6 @@ function update_1400() return Update::FAILED; } - */ - if (!DBA::e("UPDATE `post-thread-user` INNER JOIN `post-thread` ON `post-thread-user`.`uri-id` = `post-thread`.`uri-id` SET `post-thread-user`.`owner-id` = `post-thread`.`owner-id`, `post-thread-user`.`author-id` = `post-thread`.`author-id`, `post-thread-user`.`causer-id` = `post-thread`.`causer-id`, `post-thread-user`.`network` = `post-thread`.`network`, @@ -815,6 +807,5 @@ function update_1400() return Update::FAILED; } - return Update::SUCCESS; } From 896e58347d81532adf51c4f2835a967a764368e9 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 14 Feb 2021 21:57:02 +0000 Subject: [PATCH 06/25] Post update function to set the "external-id" --- src/Database/PostUpdate.php | 47 ++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/Database/PostUpdate.php b/src/Database/PostUpdate.php index a58281e48..f36ae4f62 100644 --- a/src/Database/PostUpdate.php +++ b/src/Database/PostUpdate.php @@ -27,6 +27,7 @@ use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\GServer; use Friendica\Model\Item; +use Friendica\Model\ItemURI; use Friendica\Model\Photo; use Friendica\Model\Post; use Friendica\Model\Post\Category; @@ -87,7 +88,9 @@ class PostUpdate if (!self::update1384()) { return false; } - + if (!self::update1400()) { + return false; + } return true; } @@ -766,4 +769,46 @@ class PostUpdate return false; } + + /** + * update the "hash" field in the photo table + * + * @return bool "true" when the job is done + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws \ImagickException + */ + private static function update1400() + { + // Was the script completed? + if (DI::config()->get("system", "post_update_version") >= 1400) { + return true; + } + + $condition = ["`extid` != ? AND EXISTS(SELECT `id` FROM `post-user` WHERE `uri-id` = `item`.`uri-id` AND `uid` = `item`.`uid` AND `external-id` IS NULL)", '']; + Logger::info('Start', ['rest' => DBA::count('item', $condition)]); + + $rows = 0; + $items = DBA::select('item', ['uri-id', 'uid', 'extid'], $condition, ['order' => ['id'], 'limit' => 10000]); + + if (DBA::errorNo() != 0) { + Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]); + return false; + } + + while ($item = DBA::fetch($items)) { + Post::update(['external-id' => ItemURI::getIdByURI($item['extid'])], ['uri-id' => $item['uri-id'], 'uid' => $item['uid']]); + ++$rows; + } + DBA::close($items); + + Logger::info('Processed', ['rows' => $rows]); + + if ($rows <= 100) { + DI::config()->set("system", "post_update_version", 1384); + Logger::info('Done'); + return true; + } + + return false; + } } From 5f3c00271ada42b60512395faa8f49a21be4b3d0 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 14 Feb 2021 22:05:00 +0000 Subject: [PATCH 07/25] Updated database.sql --- database.sql | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/database.sql b/database.sql index 69724c3e1..3b53e76e0 100644 --- a/database.sql +++ b/database.sql @@ -1588,12 +1588,11 @@ CREATE TABLE IF NOT EXISTS `workerqueue` ( -- DROP VIEW IF EXISTS `post-view`; CREATE VIEW `post-view` AS SELECT - `item`.`id` AS `id`, + `post-user`.`id` AS `id`, `item`.`id` AS `item-id`, `post-user`.`id` AS `post-user-id`, `post-user`.`uid` AS `uid`, - `item`.`parent` AS `parent`, - `parent-post`.`id` AS `parent-user-id`, + `parent-post`.`id` AS `parent`, `item-uri`.`uri` AS `uri`, `post-user`.`uri-id` AS `uri-id`, `parent-item-uri`.`uri` AS `parent-uri`, @@ -1747,13 +1746,12 @@ CREATE VIEW `post-view` AS SELECT -- DROP VIEW IF EXISTS `post-thread-view`; CREATE VIEW `post-thread-view` AS SELECT - `item`.`id` AS `id`, + `post-user`.`id` AS `id`, `item`.`id` AS `item-id`, - `item`.`id` AS `iid`, + `post-user`.`id` AS `iid`, `post-user`.`id` AS `post-user-id`, `post-thread-user`.`uid` AS `uid`, - `item`.`parent` AS `parent`, - `parent-post`.`id` AS `parent-user-id`, + `parent-post`.`id` AS `parent`, `item-uri`.`uri` AS `uri`, `post-thread-user`.`uri-id` AS `uri-id`, `parent-item-uri`.`uri` AS `parent-uri`, @@ -1938,8 +1936,7 @@ CREATE VIEW `tag-view` AS SELECT DROP VIEW IF EXISTS `network-item-view`; CREATE VIEW `network-item-view` AS SELECT `post-user`.`uri-id` AS `uri-id`, - `item`.`parent` AS `parent`, - `post-user`.`parent-uri-id` AS `parent-uri-id`, + `post-user`.`parent-uri-id` AS `parent`, `post-user`.`received` AS `received`, `post-thread-user`.`commented` AS `commented`, `post-user`.`created` AS `created`, @@ -1952,8 +1949,7 @@ CREATE VIEW `network-item-view` AS SELECT `post-user`.`contact-id` AS `contact-id`, `ownercontact`.`contact-type` AS `contact-type` 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` + STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid` INNER JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id` LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id` LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id` @@ -1970,8 +1966,7 @@ CREATE VIEW `network-item-view` AS SELECT DROP VIEW IF EXISTS `network-thread-view`; CREATE VIEW `network-thread-view` AS SELECT `post-thread-user`.`uri-id` AS `uri-id`, - `post-user`.`parent-uri-id` AS `parent-uri-id`, - `item`.`id` AS `parent`, + `post-user`.`parent-uri-id` AS `parent`, `post-thread-user`.`received` AS `received`, `post-thread-user`.`commented` AS `commented`, `post-thread-user`.`created` AS `created`, @@ -1983,7 +1978,6 @@ CREATE VIEW `network-thread-view` AS SELECT `ownercontact`.`contact-type` AS `contact-type` 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` STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id` LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id` LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id` From 2f84d874a874148ad73044a33b88783e09ae424f Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 15 Feb 2021 05:59:45 +0000 Subject: [PATCH 08/25] Test data for the "verb" table --- tests/datasets/api.fixture.php | 75 +++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 19 deletions(-) diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index 80756edbc..3a1ad6d6b 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -23,7 +23,6 @@ use Friendica\Core\Protocol; use Friendica\Model\Contact; use Friendica\Model\Item; use Friendica\Model\Notification; -use Friendica\Model\Verb; return [ // Empty these tables @@ -183,6 +182,44 @@ return [ 'guid' => '6', ], ], + 'verb' => [ + [ + 'id' => 0, + 'name' => '', + ], + [ + 'id' => 1, + 'name' => 'http://activitystrea.ms/schema/1.0/like', + ], + [ + 'id' => 2, + 'name' => 'http://purl.org/macgirvin/dfrn/1.0/dislike', + ], + [ + 'id' => 3, + 'name' => 'http://purl.org/zot/activity/attendyes', + ], + [ + 'id' => 4, + 'name' => 'http://purl.org/zot/activity/attendno', + ], + [ + 'id' => 5, + 'name' => 'http://purl.org/zot/activity/attendmaybe', + ], + [ + 'id' => 6, + 'name' => 'http://activitystrea.ms/schema/1.0/follow', + ], + [ + 'id' => 7, + 'name' => 'https://www.w3.org/ns/activitystreams#Announce', + ], + [ + 'id' => 8, + 'name' => 'http://activitystrea.ms/schema/1.0/post', + ], + ], 'post-content' => [ [ 'uri-id' => 1, @@ -225,7 +262,7 @@ return [ 'owner-id' => 42, 'author-id' => 42, 'causer-id' => 42, - 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, ], @@ -238,7 +275,7 @@ return [ 'owner-id' => 42, 'author-id' => 42, 'causer-id' => 42, - 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, ], @@ -251,7 +288,7 @@ return [ 'owner-id' => 42, 'author-id' => 43, 'causer-id' => 43, - 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, ], @@ -264,7 +301,7 @@ return [ 'owner-id' => 42, 'author-id' => 44, 'causer-id' => 44, - 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, ], @@ -277,7 +314,7 @@ return [ 'owner-id' => 42, 'author-id' => 42, 'causer-id' => 42, - 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, ], @@ -290,7 +327,7 @@ return [ 'owner-id' => 42, 'author-id' => 44, 'causer-id' => 44, - 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, ], @@ -310,7 +347,7 @@ return [ 'owner-id' => 42, 'author-id' => 42, 'causer-id' => 42, - 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, ], @@ -328,7 +365,7 @@ return [ 'owner-id' => 42, 'author-id' => 42, 'causer-id' => 42, - 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, ], @@ -346,7 +383,7 @@ return [ 'owner-id' => 42, 'author-id' => 43, 'causer-id' => 43, - 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, ], @@ -364,7 +401,7 @@ return [ 'owner-id' => 42, 'author-id' => 44, 'causer-id' => 44, - 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, ], @@ -382,7 +419,7 @@ return [ 'owner-id' => 42, 'author-id' => 42, 'causer-id' => 42, - 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, ], @@ -400,7 +437,7 @@ return [ 'owner-id' => 42, 'author-id' => 44, 'causer-id' => 44, - 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, ], @@ -418,7 +455,7 @@ return [ 'owner-id' => 42, 'author-id' => 42, 'causer-id' => 42, - 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, ], @@ -436,7 +473,7 @@ return [ 'owner-id' => 42, 'author-id' => 42, 'causer-id' => 42, - 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, ], @@ -454,7 +491,7 @@ return [ 'owner-id' => 42, 'author-id' => 43, 'causer-id' => 43, - 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, ], @@ -472,7 +509,7 @@ return [ 'owner-id' => 42, 'author-id' => 44, 'causer-id' => 44, - 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, ], @@ -490,7 +527,7 @@ return [ 'owner-id' => 42, 'author-id' => 42, 'causer-id' => 42, - 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, ], @@ -508,7 +545,7 @@ return [ 'owner-id' => 42, 'author-id' => 44, 'causer-id' => 44, - 'vid' => Verb::getID('http://activitystrea.ms/schema/1.0/post'), + 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, ], From 1778e57baf390fa29fa43bbc01c016af76e4fe05 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 15 Feb 2021 06:14:53 +0000 Subject: [PATCH 09/25] Missing field in view --- database.sql | 1 + static/dbview.config.php | 1 + tests/datasets/api.fixture.php | 10 ++++++++++ 3 files changed, 12 insertions(+) diff --git a/database.sql b/database.sql index 3b53e76e0..01f81cb0d 100644 --- a/database.sql +++ b/database.sql @@ -2152,6 +2152,7 @@ DROP VIEW IF EXISTS `tag-search-view`; CREATE VIEW `tag-search-view` AS SELECT `post-tag`.`uri-id` AS `uri-id`, `post-user`.`uid` AS `uid`, + `post-user`.`id` AS `iid`, `post-user`.`private` AS `private`, `post-user`.`wall` AS `wall`, `post-user`.`origin` AS `origin`, diff --git a/static/dbview.config.php b/static/dbview.config.php index 79a2407f4..794d96659 100644 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -587,6 +587,7 @@ "fields" => [ "uri-id" => ["post-tag", "uri-id"], "uid" => ["post-user", "uid"], + "iid" => ["post-user", "id"], "private" => ["post-user", "private"], "wall" => ["post-user", "wall"], "origin" => ["post-user", "origin"], diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index 3a1ad6d6b..3e80f7c55 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -50,6 +50,16 @@ return [ 'k' => 'worker_dont_fork', 'v' => '1', ], + [ + 'cat' => 'system', + 'k' => 'curl_timeout', + 'v' => '1', + ], + [ + 'cat' => 'system', + 'k' => 'xrd_timeout', + 'v' => '1', + ], ], 'user' => [ [ From 6771d69bb107819943999cad842ef911beacbbc9 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 15 Feb 2021 06:25:41 +0000 Subject: [PATCH 10/25] Added test data --- tests/datasets/api.fixture.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index 3e80f7c55..9287583fc 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -592,6 +592,7 @@ return [ 'author-id' => 42, 'owner-id' => 42, 'causer-id' => 42, + 'contact-id' => 42, 'network' => Protocol::DFRN, ], [ @@ -602,6 +603,7 @@ return [ 'author-id' => 43, 'owner-id' => 43, 'causer-id' => 43, + 'contact-id' => 43, 'network' => Protocol::DFRN, ], [ @@ -612,6 +614,7 @@ return [ 'author-id' => 44, 'owner-id' => 44, 'causer-id' => 44, + 'contact-id' => 44, 'network' => Protocol::DFRN, ], [ @@ -622,6 +625,7 @@ return [ 'author-id' => 42, 'owner-id' => 42, 'causer-id' => 42, + 'contact-id' => 42, 'network' => Protocol::DFRN, ], [ @@ -632,6 +636,7 @@ return [ 'author-id' => 43, 'owner-id' => 43, 'causer-id' => 43, + 'contact-id' => 43, 'network' => Protocol::DFRN, ], [ @@ -642,6 +647,7 @@ return [ 'author-id' => 44, 'owner-id' => 44, 'causer-id' => 44, + 'contact-id' => 44, 'network' => Protocol::DFRN, ], ], From bbdb0de2ad26c03b43da223d66f6f6121acc943e Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 15 Feb 2021 06:46:28 +0000 Subject: [PATCH 11/25] More test data --- tests/datasets/api.fixture.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index 9287583fc..7cff54dc0 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -345,6 +345,7 @@ return [ 'post-user' => [ [ 'id' => 1, + 'parent' => 1, 'uri-id' => 1, 'uid' => 42, 'contact-id' => 42, @@ -363,6 +364,7 @@ return [ ], [ 'id' => 2, + 'parent' => 1, 'uri-id' => 2, 'uid' => 42, 'contact-id' => 42, @@ -381,6 +383,7 @@ return [ ], [ 'id' => 3, + 'parent' => 3, 'uri-id' => 3, 'uid' => 42, 'contact-id' => 43, @@ -399,6 +402,7 @@ return [ ], [ 'id' => 4, + 'parent' => 1, 'uri-id' => 4, 'uid' => 42, 'contact-id' => 44, @@ -417,6 +421,7 @@ return [ ], [ 'id' => 5, + 'parent' => 1, 'uri-id' => 5, 'uid' => 42, 'contact-id' => 42, @@ -435,6 +440,7 @@ return [ ], [ 'id' => 6, + 'parent' => 6, 'uri-id' => 6, 'uid' => 42, 'contact-id' => 44, @@ -453,6 +459,7 @@ return [ ], [ 'id' => 7, + 'parent' => 7, 'uri-id' => 1, 'uid' => 0, 'contact-id' => 42, @@ -471,6 +478,7 @@ return [ ], [ 'id' => 8, + 'parent' => 7, 'uri-id' => 2, 'uid' => 0, 'contact-id' => 42, @@ -489,6 +497,7 @@ return [ ], [ 'id' => 9, + 'parent' => 9, 'uri-id' => 3, 'uid' => 0, 'contact-id' => 43, @@ -507,6 +516,7 @@ return [ ], [ 'id' => 10, + 'parent' => 7, 'uri-id' => 4, 'uid' => 0, 'contact-id' => 44, @@ -525,6 +535,7 @@ return [ ], [ 'id' => 11, + 'parent' => 7, 'uri-id' => 5, 'uid' => 0, 'contact-id' => 42, @@ -543,6 +554,7 @@ return [ ], [ 'id' => 12, + 'parent' => 12, 'uri-id' => 6, 'uid' => 0, 'contact-id' => 44, From 69d2a7e55dc40c18375663a08016f559e88372d2 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 15 Feb 2021 06:55:41 +0000 Subject: [PATCH 12/25] Previous stuff reverted --- tests/datasets/api.fixture.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index 7cff54dc0..9287583fc 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -345,7 +345,6 @@ return [ 'post-user' => [ [ 'id' => 1, - 'parent' => 1, 'uri-id' => 1, 'uid' => 42, 'contact-id' => 42, @@ -364,7 +363,6 @@ return [ ], [ 'id' => 2, - 'parent' => 1, 'uri-id' => 2, 'uid' => 42, 'contact-id' => 42, @@ -383,7 +381,6 @@ return [ ], [ 'id' => 3, - 'parent' => 3, 'uri-id' => 3, 'uid' => 42, 'contact-id' => 43, @@ -402,7 +399,6 @@ return [ ], [ 'id' => 4, - 'parent' => 1, 'uri-id' => 4, 'uid' => 42, 'contact-id' => 44, @@ -421,7 +417,6 @@ return [ ], [ 'id' => 5, - 'parent' => 1, 'uri-id' => 5, 'uid' => 42, 'contact-id' => 42, @@ -440,7 +435,6 @@ return [ ], [ 'id' => 6, - 'parent' => 6, 'uri-id' => 6, 'uid' => 42, 'contact-id' => 44, @@ -459,7 +453,6 @@ return [ ], [ 'id' => 7, - 'parent' => 7, 'uri-id' => 1, 'uid' => 0, 'contact-id' => 42, @@ -478,7 +471,6 @@ return [ ], [ 'id' => 8, - 'parent' => 7, 'uri-id' => 2, 'uid' => 0, 'contact-id' => 42, @@ -497,7 +489,6 @@ return [ ], [ 'id' => 9, - 'parent' => 9, 'uri-id' => 3, 'uid' => 0, 'contact-id' => 43, @@ -516,7 +507,6 @@ return [ ], [ 'id' => 10, - 'parent' => 7, 'uri-id' => 4, 'uid' => 0, 'contact-id' => 44, @@ -535,7 +525,6 @@ return [ ], [ 'id' => 11, - 'parent' => 7, 'uri-id' => 5, 'uid' => 0, 'contact-id' => 42, @@ -554,7 +543,6 @@ return [ ], [ 'id' => 12, - 'parent' => 12, 'uri-id' => 6, 'uid' => 0, 'contact-id' => 44, From d8aac470081d4b8e5b2426e59769ed5dbfd84195 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 15 Feb 2021 07:05:29 +0000 Subject: [PATCH 13/25] Testing the test --- tests/legacy/ApiTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index 265f502f0..164287794 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -2001,9 +2001,9 @@ class ApiTest extends FixtureTest */ public function testApiStatusesUserTimeline() { - $_REQUEST['max_id'] = 10; - $_REQUEST['exclude_replies'] = true; - $_REQUEST['conversation_id'] = 1; +// $_REQUEST['max_id'] = 10; +// $_REQUEST['exclude_replies'] = true; +// $_REQUEST['conversation_id'] = 1; $result = api_statuses_user_timeline('json'); self::assertNotEmpty($result['status']); foreach ($result['status'] as $status) { From c4449290224afd84db65e31dbbf3a45d722c10c4 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 15 Feb 2021 07:17:26 +0000 Subject: [PATCH 14/25] Searching test error --- include/api.php | 3 ++- tests/legacy/ApiTest.php | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/api.php b/include/api.php index 130c420e4..10859475e 100644 --- a/include/api.php +++ b/include/api.php @@ -2264,7 +2264,8 @@ function api_statuses_user_timeline($type) } $params = ['order' => ['id' => true], 'limit' => [$start, $count]]; - $statuses = Post::selectForUser(api_user(), [], $condition, $params); +// $statuses = Post::selectForUser(api_user(), [], $condition, $params); + $statuses = Post::select([], $condition, $params); $ret = api_format_items(Post::toArray($statuses), $user_info, true, $type); diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index 164287794..265f502f0 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -2001,9 +2001,9 @@ class ApiTest extends FixtureTest */ public function testApiStatusesUserTimeline() { -// $_REQUEST['max_id'] = 10; -// $_REQUEST['exclude_replies'] = true; -// $_REQUEST['conversation_id'] = 1; + $_REQUEST['max_id'] = 10; + $_REQUEST['exclude_replies'] = true; + $_REQUEST['conversation_id'] = 1; $result = api_statuses_user_timeline('json'); self::assertNotEmpty($result['status']); foreach ($result['status'] as $status) { From a1a44716326fedc0bed8261f168904899c937da1 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 15 Feb 2021 07:25:45 +0000 Subject: [PATCH 15/25] Fix SQL query --- src/Worker/ExpirePosts.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Worker/ExpirePosts.php b/src/Worker/ExpirePosts.php index 0535c223b..33c8e542a 100644 --- a/src/Worker/ExpirePosts.php +++ b/src/Worker/ExpirePosts.php @@ -59,9 +59,9 @@ class ExpirePosts AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `post-user` INNER JOIN `contact` ON `contact`.`id` = `contact-id` AND `notify_new_posts` WHERE `parent-uri-id` = `post-thread`.`uri-id`) AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `post-user` - WHERE (`origin` OR `event-id` != 0 OR `post-type` = ?) AND `parent-uri-id` = `post-thread`.`uri-id`)) + WHERE (`origin` OR `event-id` != 0 OR `post-type` = ?) AND `parent-uri-id` = `post-thread`.`uri-id`) AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-content` - WHERE (`resource-id` != 0) AND `uri-id` = `post-thread`.`uri-id`)) + WHERE `resource-id` != 0 AND `uri-id` = `post-thread`.`uri-id`) ORDER BY `id` LIMIT ?", $expire_days, Item::PT_PERSONAL_NOTE, $limit); $rows = DBA::affectedRows(); From 7117ada2bc6d4ac4756f8d3eba706bb8f0c7b20f Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 15 Feb 2021 07:25:55 +0000 Subject: [PATCH 16/25] Test the test --- include/api.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/api.php b/include/api.php index 10859475e..d408fc40e 100644 --- a/include/api.php +++ b/include/api.php @@ -2262,10 +2262,9 @@ function api_statuses_user_timeline($type) $condition[0] .= " AND `id` <= ?"; $condition[] = $max_id; } - + $condition = []; // test $params = ['order' => ['id' => true], 'limit' => [$start, $count]]; -// $statuses = Post::selectForUser(api_user(), [], $condition, $params); - $statuses = Post::select([], $condition, $params); + $statuses = Post::selectForUser(api_user(), [], $condition, $params); $ret = api_format_items(Post::toArray($statuses), $user_info, true, $type); From b51dc4dd9130e679813a99ab3b9a82db401de8a8 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 15 Feb 2021 07:43:54 +0000 Subject: [PATCH 17/25] Reverting the test --- include/api.php | 1 - 1 file changed, 1 deletion(-) diff --git a/include/api.php b/include/api.php index d408fc40e..d56599ce6 100644 --- a/include/api.php +++ b/include/api.php @@ -2262,7 +2262,6 @@ function api_statuses_user_timeline($type) $condition[0] .= " AND `id` <= ?"; $condition[] = $max_id; } - $condition = []; // test $params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $statuses = Post::selectForUser(api_user(), [], $condition, $params); From 2b76ff61adf1f0adc7fd490c015655c91302bcad Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 15 Feb 2021 07:44:51 +0000 Subject: [PATCH 18/25] Avoiding notice --- src/Worker/Delivery.php | 4 ++-- src/Worker/Notifier.php | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index e2db058ea..af04d91c5 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -55,6 +55,8 @@ 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)) { @@ -69,8 +71,6 @@ class Delivery $sender_uid = $post['uid']; $post_uriid = $post['uri-id']; } - } else { - $target_id = $post_uriid; } $top_level = false; diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index f225adf11..896916ede 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -59,6 +59,8 @@ 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)) { @@ -67,15 +69,12 @@ class Notifier } $target_id = $post['id']; } elseif (!in_array($cmd, [Delivery::MAIL, Delivery::SUGGESTION, Delivery::REMOVAL, Delivery::RELOCATION])) { - $post = Post::selectFirst(['id'], ['item-id' => $post_uriid]); $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']; } - } else { - $target_id = $post_uriid; } $top_level = false; From 2b17e36a6762c205c2cd777e0386c42ae83610f2 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 15 Feb 2021 10:29:58 +0000 Subject: [PATCH 19/25] Rever item reshare handling, fixed database --- src/Model/Item.php | 2 +- src/Worker/ExpirePosts.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 397ea0b31..8fc7ce135 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1146,7 +1146,7 @@ class Item } $cid = Contact::getIdForURL($author['url'], $item['uid']); - if (empty($cid) || (!Contact::isSharing($cid, $item['uid'] && in_array($author['network'], Protocol::FEDERATED)))) { + if (empty($cid) || !Contact::isSharing($cid, $item['uid'])) { Logger::info('The resharer is not a following contact: quit', ['resharer' => $author['url'], 'uid' => $item['uid'], 'cid' => $cid]); return; } diff --git a/src/Worker/ExpirePosts.php b/src/Worker/ExpirePosts.php index 33c8e542a..8d50c5d9d 100644 --- a/src/Worker/ExpirePosts.php +++ b/src/Worker/ExpirePosts.php @@ -61,7 +61,7 @@ class ExpirePosts AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `post-user` WHERE (`origin` OR `event-id` != 0 OR `post-type` = ?) AND `parent-uri-id` = `post-thread`.`uri-id`) AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-content` - WHERE `resource-id` != 0 AND `uri-id` = `post-thread`.`uri-id`) + WHERE `resource-id` != 0 AND `uri-id` = `post-thread`.`uri-id`)) ORDER BY `id` LIMIT ?", $expire_days, Item::PT_PERSONAL_NOTE, $limit); $rows = DBA::affectedRows(); From 0beec80405c13fe46c6e0da36d783f5d524c88b0 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 15 Feb 2021 11:03:22 +0000 Subject: [PATCH 20/25] Fix updating the thread --- src/Model/Item.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 8fc7ce135..40208e4e5 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1062,11 +1062,13 @@ class Item } if ($update_commented) { - Post::update(['commented' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()], ['id' => $post_user_id]); + $fields = ['commented' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()]; } else { - Post::update(['changed' => DateTimeFormat::utcNow()], ['uri-id' => $posted_item['parent-uri-id'], 'uid' => $posted_item['uid']]); + $fields = ['changed' => DateTimeFormat::utcNow()]; } + Post::update($fields, ['uri-id' => $posted_item['parent-uri-id'], 'uid' => $posted_item['uid']]); + // In that function we check if this is a forum post. Additionally we delete the item under certain circumstances if (self::tagDeliver($posted_item['uid'], $post_user_id)) { // Get the user information for the logging From 0f841484139ee8a711f342917af8f19d0e2ec350 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 15 Feb 2021 12:40:05 +0000 Subject: [PATCH 21/25] Some more test data tests --- tests/datasets/api.fixture.php | 61 +++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index 9287583fc..ca54ff0a9 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -275,6 +275,7 @@ return [ 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, + 'deleted' => 0, ], [ 'uri-id' => 2, @@ -288,6 +289,7 @@ return [ 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, + 'deleted' => 0, ], [ 'uri-id' => 3, @@ -301,6 +303,7 @@ return [ 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, + 'deleted' => 0, ], [ 'uri-id' => 4, @@ -314,6 +317,7 @@ return [ 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, + 'deleted' => 0, ], [ 'uri-id' => 5, @@ -327,6 +331,7 @@ return [ 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, + 'deleted' => 0, ], [ 'uri-id' => 6, @@ -340,26 +345,27 @@ return [ 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, + 'deleted' => 0, ], ], 'post-user' => [ [ 'id' => 1, 'uri-id' => 1, - 'uid' => 42, + 'visible' => 1, 'contact-id' => 42, + 'author-id' => 42, + 'owner-id' => 42, + 'causer-id' => 42, + 'uid' => 42, + 'vid' => 8, 'unseen' => 1, - 'origin' => 1, 'parent-uri-id' => 1, 'thr-parent-id' => 1, + 'private' => Item::PUBLIC, 'gravity' => GRAVITY_PARENT, 'network' => Protocol::DFRN, - 'owner-id' => 42, - 'author-id' => 42, - 'causer-id' => 42, - 'vid' => 8, - 'private' => Item::PUBLIC, - 'visible' => 1, + 'origin' => 1, ], [ 'id' => 2, @@ -378,6 +384,7 @@ return [ 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, + 'deleted' => 0, ], [ 'id' => 3, @@ -396,6 +403,7 @@ return [ 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, + 'deleted' => 0, ], [ 'id' => 4, @@ -414,6 +422,7 @@ return [ 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, + 'deleted' => 0, ], [ 'id' => 5, @@ -432,6 +441,7 @@ return [ 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, + 'deleted' => 0, ], [ 'id' => 6, @@ -450,6 +460,7 @@ return [ 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, + 'deleted' => 0, ], [ 'id' => 7, @@ -468,6 +479,7 @@ return [ 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, + 'deleted' => 0, ], [ 'id' => 8, @@ -486,6 +498,7 @@ return [ 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, + 'deleted' => 0, ], [ 'id' => 9, @@ -504,6 +517,7 @@ return [ 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, + 'deleted' => 0, ], [ 'id' => 10, @@ -522,6 +536,7 @@ return [ 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, + 'deleted' => 0, ], [ 'id' => 11, @@ -540,24 +555,26 @@ return [ 'vid' => 8, 'private' => Item::PUBLIC, 'visible' => 1, + 'deleted' => 0, ], [ 'id' => 12, 'uri-id' => 6, - 'uid' => 0, + 'visible' => 1, 'contact-id' => 44, + 'author-id' => 44, + 'owner-id' => 42, + 'causer-id' => 44, + 'uid' => 0, + 'vid' => 8, 'unseen' => 0, - 'origin' => 0, 'parent-uri-id' => 6, 'thr-parent-id' => 6, + 'private' => Item::PUBLIC, 'gravity' => GRAVITY_PARENT, 'network' => Protocol::DFRN, - 'owner-id' => 42, - 'author-id' => 44, - 'causer-id' => 44, - 'vid' => 8, - 'private' => Item::PUBLIC, - 'visible' => 1, + 'origin' => 0, + 'deleted' => 0, ], ], 'post-thread' => [ @@ -594,6 +611,8 @@ return [ 'causer-id' => 42, 'contact-id' => 42, 'network' => Protocol::DFRN, + 'starred' => 1, + 'origin' => 1, ], [ 'uri-id' => 3, @@ -605,6 +624,8 @@ return [ 'causer-id' => 43, 'contact-id' => 43, 'network' => Protocol::DFRN, + 'starred' => 0, + 'origin' => 1, ], [ 'uri-id' => 6, @@ -616,6 +637,8 @@ return [ 'causer-id' => 44, 'contact-id' => 44, 'network' => Protocol::DFRN, + 'starred' => 0, + 'origin' => 1, ], [ 'uri-id' => 1, @@ -627,6 +650,8 @@ return [ 'causer-id' => 42, 'contact-id' => 42, 'network' => Protocol::DFRN, + 'starred' => 0, + 'origin' => 0, ], [ 'uri-id' => 3, @@ -638,6 +663,8 @@ return [ 'causer-id' => 43, 'contact-id' => 43, 'network' => Protocol::DFRN, + 'starred' => 0, + 'origin' => 0, ], [ 'uri-id' => 6, @@ -649,6 +676,8 @@ return [ 'causer-id' => 44, 'contact-id' => 44, 'network' => Protocol::DFRN, + 'starred' => 0, + 'origin' => 0, ], ], 'notify' => [ From e1c1744dd17baa53de7c9afbc7ada0244d9adc45 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 15 Feb 2021 12:43:23 +0000 Subject: [PATCH 22/25] "wall" in test data --- tests/datasets/api.fixture.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index ca54ff0a9..15e31d88b 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -365,6 +365,7 @@ return [ 'private' => Item::PUBLIC, 'gravity' => GRAVITY_PARENT, 'network' => Protocol::DFRN, + 'wall' => 1, 'origin' => 1, ], [ @@ -385,6 +386,7 @@ return [ 'private' => Item::PUBLIC, 'visible' => 1, 'deleted' => 0, + 'wall' => 1, ], [ 'id' => 3, @@ -404,6 +406,7 @@ return [ 'private' => Item::PUBLIC, 'visible' => 1, 'deleted' => 0, + 'wall' => 1, ], [ 'id' => 4, @@ -423,6 +426,7 @@ return [ 'private' => Item::PUBLIC, 'visible' => 1, 'deleted' => 0, + 'wall' => 1, ], [ 'id' => 5, @@ -442,6 +446,7 @@ return [ 'private' => Item::PUBLIC, 'visible' => 1, 'deleted' => 0, + 'wall' => 1, ], [ 'id' => 6, @@ -461,6 +466,7 @@ return [ 'private' => Item::PUBLIC, 'visible' => 1, 'deleted' => 0, + 'wall' => 1, ], [ 'id' => 7, @@ -480,6 +486,7 @@ return [ 'private' => Item::PUBLIC, 'visible' => 1, 'deleted' => 0, + 'wall' => 0, ], [ 'id' => 8, @@ -499,6 +506,7 @@ return [ 'private' => Item::PUBLIC, 'visible' => 1, 'deleted' => 0, + 'wall' => 0, ], [ 'id' => 9, @@ -518,6 +526,7 @@ return [ 'private' => Item::PUBLIC, 'visible' => 1, 'deleted' => 0, + 'wall' => 0, ], [ 'id' => 10, @@ -537,6 +546,7 @@ return [ 'private' => Item::PUBLIC, 'visible' => 1, 'deleted' => 0, + 'wall' => 0, ], [ 'id' => 11, @@ -556,6 +566,7 @@ return [ 'private' => Item::PUBLIC, 'visible' => 1, 'deleted' => 0, + 'wall' => 0, ], [ 'id' => 12, @@ -575,6 +586,7 @@ return [ 'network' => Protocol::DFRN, 'origin' => 0, 'deleted' => 0, + 'wall' => 0, ], ], 'post-thread' => [ From e2e87c7ad84b097c2bccc05dc9b5159b58fc1cfe Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 15 Feb 2021 15:12:49 +0000 Subject: [PATCH 23/25] Ensure that the thread-user-data does exist --- update.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/update.php b/update.php index a59f0ca13..6f796cd0f 100644 --- a/update.php +++ b/update.php @@ -799,6 +799,14 @@ function update_1400() return Update::FAILED; } + if (!DBA::e("INSERT IGNORE INTO `post-thread-user` (`uri-id`, `owner-id`, `author-id`, `causer-id`, `network`, + `created`, `received`, `changed`, `commented`, `uid`, `wall`, `contact-id`, `unseen`, `hidden`, `origin`, `psid`, `post-user-id`) + SELECT `uri-id`, `owner-id`, `author-id`, `causer-id`, `network`, `created`, `received`, `received`, `received`, + `uid`, `wall`, `contact-id`, `unseen`, `hidden`, `origin`, `psid`, `id` + FROM `post-user` WHERE `gravity` = 0 AND NOT EXISTS(SELECT `uri-id` FROM `post-thread-user` WHERE `post-user-id` = `post-user`.id)")) { + return Update::FAILED; + } + if (!DBA::e("UPDATE `post-thread-user` INNER JOIN `post-thread` ON `post-thread-user`.`uri-id` = `post-thread`.`uri-id` SET `post-thread-user`.`owner-id` = `post-thread`.`owner-id`, `post-thread-user`.`author-id` = `post-thread`.`author-id`, `post-thread-user`.`causer-id` = `post-thread`.`causer-id`, `post-thread-user`.`network` = `post-thread`.`network`, From 649901f3ead5e4cdea24c54436af3016930bc156 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 15 Feb 2021 17:34:31 +0000 Subject: [PATCH 24/25] Network update does work now again --- database.sql | 6 ++++-- static/dbview.config.php | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/database.sql b/database.sql index 01f81cb0d..3e1c44f99 100644 --- a/database.sql +++ b/database.sql @@ -1936,7 +1936,7 @@ CREATE VIEW `tag-view` AS SELECT DROP VIEW IF EXISTS `network-item-view`; CREATE VIEW `network-item-view` AS SELECT `post-user`.`uri-id` AS `uri-id`, - `post-user`.`parent-uri-id` AS `parent`, + `parent-post`.`id` AS `parent`, `post-user`.`received` AS `received`, `post-thread-user`.`commented` AS `commented`, `post-user`.`created` AS `created`, @@ -1954,6 +1954,7 @@ CREATE VIEW `network-item-view` AS SELECT LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id` LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id` INNER JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id` + LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid` WHERE `post-user`.`visible` AND NOT `post-user`.`deleted` AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`) AND (`post-user`.`hidden` IS NULL OR NOT `post-user`.`hidden`) @@ -1966,7 +1967,7 @@ CREATE VIEW `network-item-view` AS SELECT DROP VIEW IF EXISTS `network-thread-view`; CREATE VIEW `network-thread-view` AS SELECT `post-thread-user`.`uri-id` AS `uri-id`, - `post-user`.`parent-uri-id` AS `parent`, + `parent-post`.`id` AS `parent`, `post-thread-user`.`received` AS `received`, `post-thread-user`.`commented` AS `commented`, `post-thread-user`.`created` AS `created`, @@ -1982,6 +1983,7 @@ CREATE VIEW `network-thread-view` AS SELECT LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id` LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id` LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id` + LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid` WHERE `post-user`.`visible` AND NOT `post-user`.`deleted` AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`) AND (`post-thread-user`.`hidden` IS NULL OR NOT `post-thread-user`.`hidden`) diff --git a/static/dbview.config.php b/static/dbview.config.php index 794d96659..3751e671c 100644 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -379,7 +379,7 @@ "network-item-view" => [ "fields" => [ "uri-id" => ["post-user", "uri-id"], - "parent" => ["post-user", "parent-uri-id"], + "parent" => ["parent-post", "id"], "received" => ["post-user", "received"], "commented" => ["post-thread-user", "commented"], "created" => ["post-user", "created"], @@ -398,6 +398,7 @@ LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id` LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id` INNER JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id` + LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid` WHERE `post-user`.`visible` AND NOT `post-user`.`deleted` AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`) AND (`post-user`.`hidden` IS NULL OR NOT `post-user`.`hidden`) @@ -407,7 +408,7 @@ "network-thread-view" => [ "fields" => [ "uri-id" => ["post-thread-user", "uri-id"], - "parent" => ["post-user", "parent-uri-id"], + "parent" => ["parent-post", "id"], "received" => ["post-thread-user", "received"], "commented" => ["post-thread-user", "commented"], "created" => ["post-thread-user", "created"], @@ -424,6 +425,7 @@ LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id` LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id` LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id` + LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid` WHERE `post-user`.`visible` AND NOT `post-user`.`deleted` AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`) AND (`post-thread-user`.`hidden` IS NULL OR NOT `post-thread-user`.`hidden`) From 1afc07683149deb4b2d04eb890314d6a3f15735c Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 15 Feb 2021 22:22:34 +0000 Subject: [PATCH 25/25] Set the post update version --- src/Database/PostUpdate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Database/PostUpdate.php b/src/Database/PostUpdate.php index f36ae4f62..232ee1881 100644 --- a/src/Database/PostUpdate.php +++ b/src/Database/PostUpdate.php @@ -45,7 +45,7 @@ class PostUpdate { // Needed for the helper function to read from the legacy term table const OBJECT_TYPE_POST = 1; - const VERSION = 1384; + const VERSION = 1400; /** * Calls the post update functions @@ -804,7 +804,7 @@ class PostUpdate Logger::info('Processed', ['rows' => $rows]); if ($rows <= 100) { - DI::config()->set("system", "post_update_version", 1384); + DI::config()->set("system", "post_update_version", 1400); Logger::info('Done'); return true; }