The thread table is replaced by post-thread and post-thread-user

This commit is contained in:
Michael 2021-02-04 05:51:25 +00:00
parent e561cad844
commit 5e846dd7c2
13 changed files with 358 additions and 153 deletions

View file

@ -979,6 +979,10 @@ class Item
Post\Media::insertFromAttachment($item['uri-id'], $item['attach']);
}
if ($item['gravity'] == GRAVITY_PARENT) {
Post\Thread::insert($item['uri-id'], $item);
}
if (!in_array($item['verb'], self::ACTIVITIES)) {
Post\Content::insert($item['uri-id'], $item);
}
@ -2203,9 +2207,9 @@ class Item
public static function firstPostDate($uid, $wall = false)
{
$condition = ['uid' => $uid, 'wall' => $wall, 'deleted' => false, 'visible' => true, 'moderated' => false];
$condition = ['gravity' => GRAVITY_PARENT, 'uid' => $uid, 'wall' => $wall, 'deleted' => false, 'visible' => true, 'moderated' => false];
$params = ['order' => ['received' => false]];
$thread = DBA::selectFirst('thread', ['received'], $condition, $params);
$thread = Post::selectFirst(['received'], $condition, $params);
if (DBA::isResult($thread)) {
return substr(DateTimeFormat::local($thread['received']), 0, 10);
}

View file

@ -194,7 +194,7 @@ class Post
'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-thread-view') {
if ($view != 'post-view') {
$selected = array_merge($selected, ['ignored', 'iid']);
}
}
@ -448,6 +448,18 @@ class Post
$affected = max($affected, DBA::affectedRows());
}
$update_fields = DBStructure::getFieldsForTable('post-thread', $fields);
if (!empty($update_fields)) {
$rows = DBA::selectToArray('post-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]);
$uriids = array_column($rows, 'uri-id');
if (!DBA::update('post-thread', $update_fields, ['uri-id' => $uriids])) {
DBA::rollback();
Logger::notice('Updating post-thread failed', ['fields' => $update_fields, 'condition' => $condition]);
return false;
}
$affected = max($affected, DBA::affectedRows());
}
$update_fields = DBStructure::getFieldsForTable('post-thread-user', $fields);
if (!empty($update_fields)) {
$rows = DBA::selectToArray('post-view', ['post-user-id'], $thread_condition);

97
src/Model/Post/Thread.php Normal file
View file

@ -0,0 +1,97 @@
<?php
/**
* @copyright Copyright (C) 2020, Friendica
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Model\Post;
use \BadMethodCallException;
use Friendica\Core\Protocol;
use Friendica\Database\Database;
use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use Friendica\Model\Post;
class Thread
{
/**
* Insert a new post-thread entry
*
* @param integer $uri_id
* @param array $fields
* @return bool success
* @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-thread', $data);
// Additionally assign the key fields
$fields['uri-id'] = $uri_id;
return DBA::insert('post-thread', $fields, Database::INSERT_IGNORE);
}
/**
* Update a post-thread entry
*
* @param integer $uri_id
* @param array $data
* @param bool $insert_if_missing
* @return bool
* @throws \Exception
*/
public static function update(int $uri_id, array $data = [], bool $insert_if_missing = false)
{
if (empty($uri_id)) {
throw new BadMethodCallException('Empty URI_id');
}
$fields = DBStructure::getFieldsForTable('post-thread', $data);
// Remove the key fields
unset($fields['uri-id']);
if (empty($fields)) {
return true;
}
return DBA::update('post-thread', $fields, ['uri-id' => $uri_id], $insert_if_missing ? true : []);
}
/**
* Delete a row from the post-thread 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-thread', $conditions, $options);
}
}