Browse Source

Get rid of the "item" table, enhanced "post" tables

pull/9930/head
Michael 6 months ago
parent
commit
ce6ad1aa73
  1. 286
      database.sql
  2. 14
      mod/item.php
  3. 2
      src/Content/Widget/TagCloud.php
  4. 4
      src/Factory/Api/Mastodon/Status.php
  5. 2
      src/Model/Contact.php
  6. 58
      src/Model/Item.php
  7. 81
      src/Model/Post.php
  8. 4
      src/Module/Conversation/Network.php
  9. 2
      src/Module/Profile/Status.php
  10. 3
      src/Module/Search/Filed.php
  11. 2
      src/Module/Search/Index.php
  12. 2
      src/Module/Update/Profile.php
  13. 5
      src/Protocol/ActivityPub/Processor.php
  14. 2
      src/Protocol/ActivityPub/Receiver.php
  15. 12
      src/Protocol/ActivityPub/Transmitter.php
  16. 6
      src/Protocol/Feed.php
  17. 5
      src/Worker/Delivery.php
  18. 10
      src/Worker/Notifier.php
  19. 9
      src/Worker/RemoveContact.php
  20. 102
      static/dbstructure.config.php
  21. 231
      static/dbview.config.php
  22. 81
      tests/datasets/api.fixture.php
  23. 48
      update.php

286
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`)

14
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;
/*

2
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

4
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 : '.'));
}

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

58
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)) {

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

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

2
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]];

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

2
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)) {

2
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

5
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;
}

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

12
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 [];
}

6
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;
}

5
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) {

10
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']);
}
}

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

102
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"],
"