Use verb instead of vid

This commit is contained in:
Michael 2023-12-31 05:01:35 +00:00
parent edb0986d17
commit 22b01992d2
8 changed files with 58 additions and 27 deletions

View file

@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 2024.03-dev (Yellow Archangel)
-- DB_UPDATE_VERSION 1543
-- DB_UPDATE_VERSION 1544
-- ------------------------------------------
@ -2025,6 +2025,20 @@ CREATE VIEW `circle-member-view` AS SELECT
INNER JOIN `contact` ON `group_member`.`contact-id` = `contact`.`id`
INNER JOIN `group` ON `group_member`.`gid` = `group`.`id`;
--
-- VIEW post-counts-view
--
DROP VIEW IF EXISTS `post-counts-view`;
CREATE VIEW `post-counts-view` AS SELECT
`post-counts`.`uri-id` AS `uri-id`,
`post-counts`.`vid` AS `vid`,
`verb`.`name` AS `verb`,
`post-counts`.`reaction` AS `reaction`,
`post-counts`.`parent-uri-id` AS `parent-uri-id`,
`post-counts`.`count` AS `count`
FROM `post-counts`
INNER JOIN `verb` ON `verb`.`id` = `post-counts`.`vid`;
--
-- VIEW post-timeline-view
--

View file

@ -874,7 +874,7 @@ class Conversation
$condition = DBA::mergeConditions(
$condition,
["`uid` IN (0, ?) AND (NOT `vid` IN (?, ?, ?) OR `vid` IS NULL)", $uid, Verb::getID(Activity::FOLLOW), Verb::getID(Activity::VIEW), Verb::getID(Activity::READ)]
["`uid` IN (0, ?) AND (NOT `verb` IN (?, ?, ?) OR `verb` IS NULL)", $uid, Activity::FOLLOW, Activity::VIEW, Activity::READ]
);
$condition = DBA::mergeConditions($condition, ["(`uid` != ? OR `private` != ?)", 0, ItemModel::PRIVATE]);
@ -1082,7 +1082,7 @@ class Conversation
{
$counts = [];
foreach (Post\Counts::get(['parent-uri-id' => $uriids, 'vid' => Verb::getID(Activity::POST)]) as $count) {
foreach (Post\Counts::get(['parent-uri-id' => $uriids, 'verb' => Activity::POST]) as $count) {
$counts[$count['parent-uri-id']] = ($counts[$count['parent-uri-id']] ?? 0) + $count['count'];
}

View file

@ -52,7 +52,7 @@ class PostUpdate
// Needed for the helper function to read from the legacy term table
const OBJECT_TYPE_POST = 1;
const VERSION = 1543;
const VERSION = 1544;
/**
* Calls the post update functions
@ -125,7 +125,7 @@ class PostUpdate
if (!self::update1507()) {
return false;
}
if (!self::update1543()) {
if (!self::update1544()) {
return false;
}
return true;
@ -1315,20 +1315,24 @@ class PostUpdate
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
private static function update1543()
private static function update1544()
{
// Was the script completed?
if (DI::keyValue()->get('post_update_version') >= 1543) {
if (DI::keyValue()->get('post_update_version') >= 1544) {
return true;
}
$id = DI::keyValue()->get('post_update_version_1543_id') ?? 0;
$id = (int)(DI::keyValue()->get('post_update_version_1544_id') ?? 0);
if ($id == 0) {
$post = Post::selectFirstPost(['uri-id'], [], ['order' => ['uri-id' => true]]);
$id = (int)($post['uri-id'] ?? 0);
}
Logger::info('Start', ['uri-id' => $id]);
$rows = 0;
$posts = Post::selectPosts(['uri-id', 'parent-uri-id'], ["`uri-id` > ? AND `gravity` IN (?, ?)", $id, Item::GRAVITY_COMMENT, Item::GRAVITY_PARENT], ['order' => ['uri-id'], 'limit' => 1000]);
$posts = Post::selectPosts(['uri-id', 'parent-uri-id'], ["`uri-id` < ? AND `gravity` IN (?, ?)", $id, Item::GRAVITY_COMMENT, Item::GRAVITY_PARENT], ['order' => ['uri-id' => true], 'limit' => 1000]);
if (DBA::errorNo() != 0) {
Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
@ -1342,12 +1346,12 @@ class PostUpdate
}
DBA::close($posts);
DI::keyValue()->set('post_update_version_1543_id', $id);
DI::keyValue()->set('post_update_version_1544_id', $id);
Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
if ($rows <= 100) {
DI::keyValue()->set('post_update_version', 1543);
DI::keyValue()->set('post_update_version', 1544);
Logger::info('Done');
return true;
}

View file

@ -96,23 +96,24 @@ class Counts
$counts = [];
$activity_emoji = [
Verb::getID(Activity::LIKE) => '👍',
Verb::getID(Activity::DISLIKE) => '👎',
Verb::getID(Activity::ATTEND) => '✔️',
Verb::getID(Activity::ATTENDMAYBE) => '❓',
Verb::getID(Activity::ATTENDNO) => '❌',
Verb::getID(Activity::ANNOUNCE) => '♻',
Verb::getID(Activity::VIEW) => '📺',
Verb::getID(Activity::READ) => '📖',
Activity::LIKE => '👍',
Activity::DISLIKE => '👎',
Activity::ATTEND => '✔️',
Activity::ATTENDMAYBE => '❓',
Activity::ATTENDNO => '❌',
Activity::ANNOUNCE => '♻',
Activity::VIEW => '📺',
Activity::READ => '📖',
];
$vids = array_merge(array_keys($activity_emoji), [Verb::getID(Activity::EMOJIREACT), Verb::getID(Activity::POST)]);
$vids = array_merge(array_keys($activity_emoji), [Activity::EMOJIREACT, Activity::POST]);
$condition = DBA::mergeConditions($condition, ['vid' => $vids]);
$countquery = DBA::select('post-counts', [], $condition);
$condition = DBA::mergeConditions($condition, ['verb' => $vids]);
$countquery = DBA::select('post-counts-view', [], $condition);
while ($count = DBA::fetch($countquery)) {
if (!empty($count['reaction'])) {
$count['vid'] = Verb::getID(Activity::EMOJIREACT);
$count['verb'] = Activity::EMOJIREACT;
$count['vid'] = Verb::getID($count['verb']);
} elseif (!empty($activity_emoji[$count['vid']])) {
$count['reaction'] = $activity_emoji[$count['vid']];
}

View file

@ -435,8 +435,8 @@ class Network extends Timeline
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)", $this->circleId]);
} elseif ($this->groupContactId) {
$conditionStrings = DBA::mergeConditions($conditionStrings,
["((`contact-id` = ?) OR `uri-id` IN (SELECT `parent-uri-id` FROM `post-user-view` WHERE (`contact-id` = ? AND `gravity` = ? AND `vid` = ? AND `uid` = ?)))",
$this->groupContactId, $this->groupContactId, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), $this->session->getLocalUserId()]);
["((`contact-id` = ?) OR `uri-id` IN (SELECT `parent-uri-id` FROM `post-user-view` WHERE (`contact-id` = ? AND `gravity` = ? AND `verb` = ? AND `uid` = ?)))",
$this->groupContactId, $this->groupContactId, Item::GRAVITY_ACTIVITY, Activity::ANNOUNCE, $this->session->getLocalUserId()]);
}
// Currently only the order modes "received" and "commented" are in use

View file

@ -640,7 +640,7 @@ class Timeline extends BaseModule
$uriids = array_keys($items);
foreach (Post\Counts::get(['parent-uri-id' => $uriids, 'vid' => Verb::getID(Activity::POST)]) as $count) {
foreach (Post\Counts::get(['parent-uri-id' => $uriids, 'verb' => Activity::POST]) as $count) {
$items[$count['parent-uri-id']]['comments'] += $count['count'];
}

View file

@ -56,7 +56,7 @@ use Friendica\Database\DBA;
// This file is required several times during the test in DbaDefinition which justifies this condition
if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1543);
define('DB_UPDATE_VERSION', 1544);
}
return [

View file

@ -87,6 +87,18 @@
INNER JOIN `contact` ON `group_member`.`contact-id` = `contact`.`id`
INNER JOIN `group` ON `group_member`.`gid` = `group`.`id`"
],
"post-counts-view" => [
"fields" => [
"uri-id" => ["post-counts", "uri-id"],
"vid" => ["post-counts", "vid"],
"verb" => ["verb", "name"],
"reaction" => ["post-counts", "reaction"],
"parent-uri-id" => ["post-counts", "parent-uri-id"],
"count" => ["post-counts", "count"],
],
"query" => "FROM `post-counts`
INNER JOIN `verb` ON `verb`.`id` = `post-counts`.`vid`"
],
"post-timeline-view" => [
"fields" => [
"uid" => ["post-user", "uid"],