Merge pull request #9826 from annando/remove-icid

The "icid" field is deprecated
This commit is contained in:
Hypolite Petovan 2021-01-19 18:39:12 -05:00 committed by GitHub
commit 47bbe16d13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 45 deletions

View file

@ -1,6 +1,6 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 2021.03-dev (Red Hot Poker) -- Friendica 2021.03-dev (Red Hot Poker)
-- DB_UPDATE_VERSION 1392 -- DB_UPDATE_VERSION 1393
-- ------------------------------------------ -- ------------------------------------------
@ -686,7 +686,6 @@ CREATE TABLE IF NOT EXISTS `item` (
`owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item', `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', `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', `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',
`icid` int unsigned COMMENT 'Id of the item-content table entry that contains the whole item content',
`vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs', `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
`extid` varchar(255) NOT NULL DEFAULT '' COMMENT '', `extid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)', `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)',
@ -708,6 +707,7 @@ CREATE TABLE IF NOT EXISTS `item` (
`resource-id` varchar(32) NOT NULL DEFAULT '' COMMENT 'Used to link other tables to items, it identifies the linked resource (e.g. photo) and if set must also set resource_type', `resource-id` varchar(32) NOT NULL DEFAULT '' COMMENT 'Used to link other tables to items, it identifies the linked resource (e.g. photo) and if set must also set resource_type',
`event-id` int unsigned COMMENT 'Used to link to the event.id', `event-id` int unsigned COMMENT 'Used to link to the event.id',
`iaid` int unsigned COMMENT 'Deprecated', `iaid` int unsigned COMMENT 'Deprecated',
`icid` int unsigned COMMENT 'Deprecated',
`attach` mediumtext COMMENT 'Deprecated', `attach` mediumtext COMMENT 'Deprecated',
`allow_cid` mediumtext COMMENT 'Deprecated', `allow_cid` mediumtext COMMENT 'Deprecated',
`allow_gid` mediumtext COMMENT 'Deprecated', `allow_gid` mediumtext COMMENT 'Deprecated',
@ -765,8 +765,6 @@ CREATE TABLE IF NOT EXISTS `item` (
INDEX `uid_unseen_wall` (`uid`,`unseen`,`wall`), INDEX `uid_unseen_wall` (`uid`,`unseen`,`wall`),
INDEX `mention_uid_id` (`mention`,`uid`,`id`), INDEX `mention_uid_id` (`mention`,`uid`,`id`),
INDEX `uid_eventid` (`uid`,`event-id`), INDEX `uid_eventid` (`uid`,`event-id`),
INDEX `icid` (`icid`),
INDEX `iaid` (`iaid`),
INDEX `vid` (`vid`), INDEX `vid` (`vid`),
INDEX `psid_wall` (`psid`,`wall`), INDEX `psid_wall` (`psid`,`wall`),
INDEX `uri-id` (`uri-id`), INDEX `uri-id` (`uri-id`),
@ -1530,7 +1528,6 @@ CREATE VIEW `post-view` AS SELECT
`item`.`mention` AS `mention`, `item`.`mention` AS `mention`,
`item`.`global` AS `global`, `item`.`global` AS `global`,
`item`.`network` AS `network`, `item`.`network` AS `network`,
`item`.`icid` AS `icid`,
`item`.`vid` AS `vid`, `item`.`vid` AS `vid`,
`item`.`psid` AS `psid`, `item`.`psid` AS `psid`,
`item`.`attach` AS `attach`, `item`.`attach` AS `attach`,
@ -1691,7 +1688,6 @@ CREATE VIEW `post-thread-view` AS SELECT
`thread`.`mention` AS `mention`, `thread`.`mention` AS `mention`,
`item`.`global` AS `global`, `item`.`global` AS `global`,
`thread`.`network` AS `network`, `thread`.`network` AS `network`,
`item`.`icid` AS `icid`,
`item`.`vid` AS `vid`, `item`.`vid` AS `vid`,
`item`.`psid` AS `psid`, `item`.`psid` AS `psid`,
`item`.`attach` AS `attach`, `item`.`attach` AS `attach`,

View file

@ -31,6 +31,7 @@ use Friendica\Core\Session;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Model\Tag; use Friendica\Model\Tag;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\Database;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Database\DBStructure; use Friendica\Database\DBStructure;
use Friendica\DI; use Friendica\DI;
@ -108,7 +109,7 @@ class Item
// All fields in the item table // All fields in the item table
const ITEM_FIELDLIST = ['id', 'uid', 'parent', 'uri', 'parent-uri', 'thr-parent', const ITEM_FIELDLIST = ['id', 'uid', 'parent', 'uri', 'parent-uri', 'thr-parent',
'guid', 'uri-id', 'parent-uri-id', 'thr-parent-id', 'vid', 'guid', 'uri-id', 'parent-uri-id', 'thr-parent-id', 'vid',
'contact-id', 'type', 'wall', 'gravity', 'extid', 'icid', 'psid', 'contact-id', 'type', 'wall', 'gravity', 'extid', 'psid',
'created', 'edited', 'commented', 'received', 'changed', 'verb', 'created', 'edited', 'commented', 'received', 'changed', 'verb',
'postopts', 'plink', 'resource-id', 'event-id', 'inform', 'postopts', 'plink', 'resource-id', 'event-id', 'inform',
'file', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type', 'file', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type',
@ -202,7 +203,7 @@ class Item
// We cannot simply expand the condition to check for origin entries // We cannot simply expand the condition to check for origin entries
// The condition needn't to be a simple array but could be a complex condition. // The condition needn't to be a simple array but could be a complex condition.
// And we have to execute this query before the update to ensure to fetch the same data. // And we have to execute this query before the update to ensure to fetch the same data.
$items = DBA::select('item', ['id', 'origin', 'uri', 'uri-id', 'icid', 'uid', 'file'], $condition); $items = DBA::select('item', ['id', 'origin', 'uri', 'uri-id', 'uid', 'file'], $condition);
$content_fields = []; $content_fields = [];
foreach (array_merge(self::CONTENT_FIELDLIST, self::MIXED_CONTENT_FIELDLIST) as $field) { foreach (array_merge(self::CONTENT_FIELDLIST, self::MIXED_CONTENT_FIELDLIST) as $field) {
@ -264,14 +265,6 @@ class Item
} }
self::updateContent($content_fields, ['uri-id' => $item['uri-id']]); self::updateContent($content_fields, ['uri-id' => $item['uri-id']]);
if (empty($item['icid'])) {
$item_content = DBA::selectFirst('item-content', [], ['uri-id' => $item['uri-id']]);
if (DBA::isResult($item_content)) {
$item_fields = ['icid' => $item_content['id']];
DBA::update('item', $item_fields, ['id' => $item['id']]);
}
}
} }
if (!is_null($files)) { if (!is_null($files)) {
@ -366,8 +359,7 @@ class Item
// locate item to be deleted // locate item to be deleted
$fields = ['id', 'uri', 'uri-id', 'uid', 'parent', 'parent-uri', 'origin', $fields = ['id', 'uri', 'uri-id', 'uid', 'parent', 'parent-uri', 'origin',
'deleted', 'file', 'resource-id', 'event-id', 'deleted', 'file', 'resource-id', 'event-id',
'verb', 'object-type', 'object', 'target', 'contact-id', 'verb', 'object-type', 'object', 'target', 'contact-id', 'psid', 'gravity'];
'icid', 'psid', 'gravity'];
$item = Post::selectFirst($fields, ['id' => $item_id]); $item = Post::selectFirst($fields, ['id' => $item_id]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
Logger::info('Item not found.', ['id' => $item_id]); Logger::info('Item not found.', ['id' => $item_id]);
@ -1123,13 +1115,10 @@ class Item
$notify_type = Delivery::POST; $notify_type = Delivery::POST;
} }
if (!in_array($item['verb'], self::ACTIVITIES)) { if (!in_array($item['verb'], self::ACTIVITIES) && !self::insertContent($item)) {
$item['icid'] = self::insertContent($item); // This shouldn't happen
if (empty($item['icid'])) { Logger::warning('No content stored, quitting', ['guid' => $item['guid'], 'uri-id' => $item['uri-id'], 'causer-id' => ($item['causer-id'] ?? 0), 'post-type' => $item['post-type'], 'network' => $item['network']]);
// This shouldn't happen return 0;
Logger::warning('No content stored, quitting', ['guid' => $item['guid'], 'uri-id' => $item['uri-id'], 'causer-id' => ($item['causer-id'] ?? 0), 'post-type' => $item['post-type'], 'network' => $item['network']]);
return 0;
}
} }
$body = $item['body']; $body = $item['body'];
@ -1372,6 +1361,7 @@ class Item
* Insert a new item content entry * Insert a new item content entry
* *
* @param array $item The item fields that are to be inserted * @param array $item The item fields that are to be inserted
* @return bool "true" if content was inserted or already existed
* @throws \Exception * @throws \Exception
*/ */
private static function insertContent(array $item) private static function insertContent(array $item)
@ -1384,25 +1374,23 @@ class Item
} }
} }
$item_content = DBA::selectFirst('item-content', ['id'], ['uri-id' => $item['uri-id']]); $found = DBA::exists('item-content', ['uri-id' => $item['uri-id']]);
if (DBA::isResult($item_content)) { if ($found) {
$icid = $item_content['id']; Logger::info('Existing content found', ['uri-id' => $item['uri-id'], 'uri' => $item['uri']]);
Logger::info('Existing content found', ['icid' => $icid, 'uri' => $item['uri']]); return true;
return $icid;
} }
DBA::replace('item-content', $fields); DBA::insert('item-content', $fields, Database::INSERT_IGNORE);
$item_content = DBA::selectFirst('item-content', ['id'], ['uri-id' => $item['uri-id']]); $found = DBA::exists('item-content', ['uri-id' => $item['uri-id']]);
if (DBA::isResult($item_content)) { if ($found) {
$icid = $item_content['id']; Logger::notice('Content inserted', ['uri-id' => $item['uri-id'], 'uri' => $item['uri']]);
Logger::notice('Content inserted', ['icid' => $icid, 'uri' => $item['uri']]); return true;
return $icid;
} }
// This shouldn't happen. // This shouldn't happen.
Logger::error("Content wasn't inserted", $item); Logger::error("Content wasn't inserted", $item);
return null; return false;
} }
/** /**
@ -1439,7 +1427,7 @@ class Item
*/ */
public static function distribute($itemid, $signed_text = '') public static function distribute($itemid, $signed_text = '')
{ {
$condition = ["`id` IN (SELECT `parent` FROM `item` WHERE `id` = ?)", $itemid]; $condition = ["`id` IN (SELECT `parent` FROM `post-view` WHERE `id` = ?)", $itemid];
$parent = Post::selectFirst(['owner-id'], $condition); $parent = Post::selectFirst(['owner-id'], $condition);
if (!DBA::isResult($parent)) { if (!DBA::isResult($parent)) {
return; return;

View file

@ -53,7 +53,7 @@ class Expire
// Normally we shouldn't have orphaned data at all. // Normally we shouldn't have orphaned data at all.
// If we do have some, then we have to check why. // If we do have some, then we have to check why.
Logger::log('Deleting orphaned item content - start', Logger::DEBUG); Logger::log('Deleting orphaned item content - start', Logger::DEBUG);
$condition = ["NOT EXISTS (SELECT `icid` FROM `item` WHERE `item`.`icid` = `item-content`.`id`)"]; $condition = ["NOT EXISTS (SELECT `uri-id` FROM `item` WHERE `item`.`uri-id` = `item-content`.`uri-id`)"];
DBA::delete('item-content', $condition); DBA::delete('item-content', $condition);
Logger::log('Orphaned item content deleted: ' . DBA::affectedRows(), Logger::DEBUG); Logger::log('Orphaned item content deleted: ' . DBA::affectedRows(), Logger::DEBUG);

View file

@ -55,7 +55,7 @@
use Friendica\Database\DBA; use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1392); define('DB_UPDATE_VERSION', 1393);
} }
return [ return [
@ -752,7 +752,6 @@ return [
"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"], "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"], "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"], "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"],
"icid" => ["type" => "int unsigned", "relation" => ["item-content" => "id"], "comment" => "Id of the item-content table entry that contains the whole item content"],
"vid" => ["type" => "smallint unsigned", "foreign" => ["verb" => "id", "on delete" => "restrict"], "comment" => "Id of the verb table entry that contains the activity verbs"], "vid" => ["type" => "smallint unsigned", "foreign" => ["verb" => "id", "on delete" => "restrict"], "comment" => "Id of the verb table entry that contains the activity verbs"],
"extid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "extid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"], "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
@ -777,6 +776,7 @@ return [
"event-id" => ["type" => "int unsigned", "relation" => ["event" => "id"], "comment" => "Used to link to the event.id"], "event-id" => ["type" => "int unsigned", "relation" => ["event" => "id"], "comment" => "Used to link to the event.id"],
// Deprecated fields. Will be removed in upcoming versions // Deprecated fields. Will be removed in upcoming versions
"iaid" => ["type" => "int unsigned", "comment" => "Deprecated"], "iaid" => ["type" => "int unsigned", "comment" => "Deprecated"],
"icid" => ["type" => "int unsigned", "comment" => "Deprecated"],
"attach" => ["type" => "mediumtext", "comment" => "Deprecated"], "attach" => ["type" => "mediumtext", "comment" => "Deprecated"],
"allow_cid" => ["type" => "mediumtext", "comment" => "Deprecated"], "allow_cid" => ["type" => "mediumtext", "comment" => "Deprecated"],
"allow_gid" => ["type" => "mediumtext", "comment" => "Deprecated"], "allow_gid" => ["type" => "mediumtext", "comment" => "Deprecated"],
@ -836,8 +836,6 @@ return [
"uid_unseen_wall" => ["uid", "unseen", "wall"], "uid_unseen_wall" => ["uid", "unseen", "wall"],
"mention_uid_id" => ["mention", "uid", "id"], "mention_uid_id" => ["mention", "uid", "id"],
"uid_eventid" => ["uid", "event-id"], "uid_eventid" => ["uid", "event-id"],
"icid" => ["icid"],
"iaid" => ["iaid"],
"vid" => ["vid"], "vid" => ["vid"],
"psid_wall" => ["psid", "wall"], "psid_wall" => ["psid", "wall"],
"uri-id" => ["uri-id"], "uri-id" => ["uri-id"],

View file

@ -76,7 +76,6 @@
"mention" => ["item", "mention"], "mention" => ["item", "mention"],
"global" => ["item", "global"], "global" => ["item", "global"],
"network" => ["item", "network"], "network" => ["item", "network"],
"icid" => ["item", "icid"],
"vid" => ["item", "vid"], "vid" => ["item", "vid"],
"psid" => ["item", "psid"], "psid" => ["item", "psid"],
"attach" => ["item", "attach"], "attach" => ["item", "attach"],
@ -235,7 +234,6 @@
"mention" => ["thread", "mention"], "mention" => ["thread", "mention"],
"global" => ["item", "global"], "global" => ["item", "global"],
"network" => ["thread", "network"], "network" => ["thread", "network"],
"icid" => ["item", "icid"],
"vid" => ["item", "vid"], "vid" => ["item", "vid"],
"psid" => ["item", "psid"], "psid" => ["item", "psid"],
"attach" => ["item", "attach"], "attach" => ["item", "attach"],