The "thread" table isn't used anymore

This commit is contained in:
Michael 2021-02-08 07:48:36 +00:00
commit ab5a447bc2
6 changed files with 13 additions and 202 deletions

View file

@ -80,7 +80,7 @@ class DBStructure
$old_tables = ['fserver', 'gcign', 'gcontact', 'gcontact-relation', 'gfollower' ,'glink', 'item-delivery-data',
'item-activity', 'item-content', 'item_id', 'participation', 'poll', 'poll_result', 'queue', 'retriever_rule',
'sign', 'spam', 'term', 'user-item'];
'sign', 'spam', 'term', 'thread', 'user-item'];
$tables = DBA::selectToArray(['INFORMATION_SCHEMA' => 'TABLES'], ['TABLE_NAME'],
['TABLE_SCHEMA' => DBA::databaseName(), 'TABLE_TYPE' => 'BASE TABLE']);

View file

@ -322,7 +322,6 @@ class Item
Post::update($item_fields, ['id' => $item['id']]);
Post\Category::storeTextByURIId($item['uri-id'], $item['uid'], '');
self::deleteThread($item['id'], $item['parent-uri-id']);
if (!Post::exists(["`uri-id` = ? AND `uid` != 0 AND NOT `deleted`", $item['uri-id']])) {
self::markForDeletion(['uri-id' => $item['uri-id'], 'uid' => 0, 'deleted' => false], $priority);
@ -900,7 +899,6 @@ class Item
// If its a post that originated here then tag the thread as "mention"
if ($item['origin'] && $item['uid']) {
DBA::update('post-thread-user', ['mention' => true], ['uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']]);
DBA::update('thread', ['mention' => true], ['iid' => $parent_id]);
Logger::info('tagged thread as mention', ['parent' => $parent_id, 'parent-uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']]);
}
@ -1073,12 +1071,6 @@ class Item
Post::update(['changed' => DateTimeFormat::utcNow()], ['id' => $parent_id]);
}
if ($item['gravity'] === GRAVITY_PARENT) {
self::addThread($current_post);
} else {
self::updateThread($parent_id);
}
// 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)) {
// Get the user information for the logging
@ -2423,75 +2415,6 @@ class Item
return true;
}
private static function addThread($itemid, $onlyshadow = false)
{
$fields = ['uid', 'created', 'edited', 'commented', 'received', 'changed', 'wall', 'private', 'pubmail',
'moderated', 'visible', 'starred', 'contact-id', 'post-type', 'uri-id',
'deleted', 'origin', 'forum_mode', 'mention', 'network', 'author-id', 'owner-id'];
$condition = ["`id` = ? AND (`parent` = ? OR `parent` = 0)", $itemid, $itemid];
$item = Post::selectFirst($fields, $condition);
if (!DBA::isResult($item)) {
return;
}
$item['iid'] = $itemid;
if (!$onlyshadow) {
$result = DBA::replace('thread', $item);
Logger::info('Add thread', ['item' => $itemid, 'result' => $result]);
}
}
private static function updateThread($itemid, $setmention = false)
{
$fields = ['uid', 'guid', 'created', 'edited', 'commented', 'received', 'changed', 'post-type',
'wall', 'private', 'pubmail', 'moderated', 'visible', 'starred', 'contact-id', 'uri-id',
'deleted', 'origin', 'forum_mode', 'network', 'author-id', 'owner-id'];
$item = Post::selectFirst($fields, ['id' => $itemid, 'gravity' => GRAVITY_PARENT]);
if (!DBA::isResult($item)) {
return;
}
if ($setmention) {
$item["mention"] = 1;
}
$fields = [];
foreach ($item as $field => $data) {
if (!in_array($field, ["guid"])) {
$fields[$field] = $data;
}
}
$result = DBA::update('thread', $fields, ['iid' => $itemid]);
Logger::info('Update thread', ['item' => $itemid, 'guid' => $item["guid"], 'result' => $result]);
}
private static function deleteThread($itemid, $uri_id)
{
$item = DBA::selectFirst('thread', ['uid'], ['iid' => $itemid]);
if (!DBA::isResult($item)) {
Logger::info('No thread found', ['id' => $itemid]);
return;
}
$result = DBA::delete('thread', ['iid' => $itemid], ['cascade' => false]);
Logger::info('Deleted thread', ['item' => $itemid, 'result' => $result]);
$condition = ["`uri-id` = ? AND NOT `deleted` AND NOT (`uid` IN (?, 0))", $uri_id, $item["uid"]];
if (!Post::exists($condition)) {
DBA::delete('item', ['uri-id' => $uri_id, 'uid' => 0]);
Post\User::delete(['uri-id' => $uri_id, 'uid' => 0]);
Logger::debug('Deleted shadow item', ['id' => $itemid, 'uri-id' => $uri_id]);
}
}
/**
* Fetch the SQL condition for the given user id
*

View file

@ -477,18 +477,6 @@ class Post
$affected = max($affected, DBA::affectedRows());
}
$update_fields = DBStructure::getFieldsForTable('thread', $fields);
if (!empty($update_fields)) {
$rows = DBA::selectToArray('post-view', ['id'], $thread_condition);
$ids = array_column($rows, 'id');
if (!DBA::update('thread', $update_fields, ['iid' => $ids])) {
DBA::rollback();
Logger::notice('Updating thread failed', ['fields' => $update_fields, 'condition' => $thread_condition]);
return false;
}
$affected = max($affected, DBA::affectedRows());
}
$update_fields = [];
foreach (Item::USED_FIELDLIST as $field) {
if (array_key_exists($field, $fields)) {

View file

@ -25,6 +25,7 @@ use Friendica\Core\Logger;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
class ExpirePosts
{
@ -47,21 +48,18 @@ class ExpirePosts
if (!empty($expire_days)) {
do {
Logger::notice('Start deleting expired threads', ['expiry_days' => $expire_days]);
/// @todo replace that query later
$ret = DBA::e("DELETE FROM `item-uri` WHERE `id` IN
(SELECT `uri-id` FROM `thread`
INNER JOIN `contact` ON `id` = `contact-id` AND NOT `notify_new_posts`
WHERE `thread`.`received` < UTC_TIMESTAMP() - INTERVAL ? DAY
AND NOT `thread`.`mention` AND NOT `thread`.`starred`
AND NOT `thread`.`wall` AND NOT `thread`.`origin`
AND `thread`.`uid` != 0 AND NOT `iid` IN (SELECT `parent` FROM `item`
WHERE (`item`.`starred` OR (`item`.`resource-id` != '')
OR (`item`.`event-id` != '') OR (`item`.`attach` != '')
OR `item`.`wall` OR `item`.`origin`
OR `item`.`uri-id` IN (SELECT `uri-id` FROM `post-category`
WHERE `post-category`.`uri-id` = `item`.`uri-id`))
AND `item`.`parent` = `thread`.`iid`))
ORDER BY `id` LIMIT ?", $expire_days, $limit);
(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`
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`))
ORDER BY `id` LIMIT ?", $expire_days, Item::PT_PERSONAL_NOTE, $limit);
$rows = DBA::affectedRows();
Logger::notice('Deleted expired threads', ['result' => $ret, 'rows' => $rows]);