Merge pull request #8705 from annando/thread-uri-id

Add "uri-id" to the "thread" table
This commit is contained in:
Hypolite Petovan 2020-05-28 23:59:44 -04:00 committed by GitHub
commit 0efd3dedeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 6 deletions

View File

@ -1,6 +1,6 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 2020.06-dev (Red Hot Poker) -- Friendica 2020.06-dev (Red Hot Poker)
-- DB_UPDATE_VERSION 1350 -- DB_UPDATE_VERSION 1351
-- ------------------------------------------ -- ------------------------------------------
@ -1237,6 +1237,7 @@ CREATE TABLE IF NOT EXISTS `storage` (
-- --
CREATE TABLE IF NOT EXISTS `thread` ( CREATE TABLE IF NOT EXISTS `thread` (
`iid` int unsigned NOT NULL DEFAULT 0 COMMENT 'sequential ID', `iid` int unsigned NOT NULL DEFAULT 0 COMMENT 'sequential ID',
`uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the item uri',
`uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id', `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
`contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT '', `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
`owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner', `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
@ -1272,7 +1273,9 @@ CREATE TABLE IF NOT EXISTS `thread` (
INDEX `uid_received` (`uid`,`received`), INDEX `uid_received` (`uid`,`received`),
INDEX `uid_commented` (`uid`,`commented`), INDEX `uid_commented` (`uid`,`commented`),
INDEX `uid_wall_received` (`uid`,`wall`,`received`), INDEX `uid_wall_received` (`uid`,`wall`,`received`),
INDEX `private_wall_origin_commented` (`private`,`wall`,`origin`,`commented`) INDEX `private_wall_origin_commented` (`private`,`wall`,`origin`,`commented`),
INDEX `uri-id` (`uri-id`),
FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data'; ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data';
-- --

View File

@ -3110,7 +3110,7 @@ class Item
private static function addThread($itemid, $onlyshadow = false) private static function addThread($itemid, $onlyshadow = false)
{ {
$fields = ['uid', 'created', 'edited', 'commented', 'received', 'changed', 'wall', 'private', 'pubmail', $fields = ['uid', 'created', 'edited', 'commented', 'received', 'changed', 'wall', 'private', 'pubmail',
'moderated', 'visible', 'starred', 'contact-id', 'post-type', 'moderated', 'visible', 'starred', 'contact-id', 'post-type', 'uri-id',
'deleted', 'origin', 'forum_mode', 'mention', 'network', 'author-id', 'owner-id']; 'deleted', 'origin', 'forum_mode', 'mention', 'network', 'author-id', 'owner-id'];
$condition = ["`id` = ? AND (`parent` = ? OR `parent` = 0)", $itemid, $itemid]; $condition = ["`id` = ? AND (`parent` = ? OR `parent` = 0)", $itemid, $itemid];
$item = self::selectFirst($fields, $condition); $item = self::selectFirst($fields, $condition);
@ -3131,7 +3131,7 @@ class Item
private static function updateThread($itemid, $setmention = false) private static function updateThread($itemid, $setmention = false)
{ {
$fields = ['uid', 'guid', 'created', 'edited', 'commented', 'received', 'changed', 'post-type', $fields = ['uid', 'guid', 'created', 'edited', 'commented', 'received', 'changed', 'post-type',
'wall', 'private', 'pubmail', 'moderated', 'visible', 'starred', 'contact-id', 'wall', 'private', 'pubmail', 'moderated', 'visible', 'starred', 'contact-id', 'uri-id',
'deleted', 'origin', 'forum_mode', 'network', 'author-id', 'owner-id']; 'deleted', 'origin', 'forum_mode', 'network', 'author-id', 'owner-id'];
$condition = ["`id` = ? AND (`parent` = ? OR `parent` = 0)", $itemid, $itemid]; $condition = ["`id` = ? AND (`parent` = ? OR `parent` = 0)", $itemid, $itemid];

View File

@ -54,7 +54,7 @@
use Friendica\Database\DBA; use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1350); define('DB_UPDATE_VERSION', 1351);
} }
return [ return [
@ -1343,6 +1343,7 @@ return [
"fields" => [ "fields" => [
"iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["item" => "id"], "iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["item" => "id"],
"comment" => "sequential ID"], "comment" => "sequential ID"],
"uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"], "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
"contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""], "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
"owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Item owner"], "owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Item owner"],
@ -1381,6 +1382,7 @@ return [
"uid_commented" => ["uid", "commented"], "uid_commented" => ["uid", "commented"],
"uid_wall_received" => ["uid", "wall", "received"], "uid_wall_received" => ["uid", "wall", "received"],
"private_wall_origin_commented" => ["private", "wall", "origin", "commented"], "private_wall_origin_commented" => ["private", "wall", "origin", "commented"],
"uri-id" => ["uri-id"],
] ]
], ],
"tokens" => [ "tokens" => [

View File

@ -268,6 +268,7 @@ return [
'thread' => [ 'thread' => [
[ [
'iid' => 1, 'iid' => 1,
'uri-id' => 1,
'visible' => 1, 'visible' => 1,
'contact-id' => 42, 'contact-id' => 42,
'author-id' => 42, 'author-id' => 42,
@ -277,6 +278,7 @@ return [
], ],
[ [
'iid' => 3, 'iid' => 3,
'uri-id' => 3,
'visible' => 1, 'visible' => 1,
'contact-id' => 43, 'contact-id' => 43,
'author-id' => 43, 'author-id' => 43,
@ -286,6 +288,7 @@ return [
], ],
[ [
'iid' => 6, 'iid' => 6,
'uri-id' => 6,
'visible' => 1, 'visible' => 1,
'contact-id' => 44, 'contact-id' => 44,
'author-id' => 44, 'author-id' => 44,

View File

@ -498,4 +498,13 @@ function update_1349()
} }
return Update::SUCCESS; return Update::SUCCESS;
} }
function update_1351()
{
if (!DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id` SET `thread`.`uri-id` = `item`.`uri-id`")) {
return Update::FAILED;
}
return Update::SUCCESS;
}