]> git.mxchange.org Git - friendica.git/commitdiff
Simplify query merge, changed update behaviour
authorMichael <heluecht@pirati.ca>
Sat, 9 Sep 2023 12:00:22 +0000 (12:00 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 9 Sep 2023 12:00:22 +0000 (12:00 +0000)
src/Module/Conversation/Channel.php
src/Module/Conversation/Community.php
src/Module/Conversation/Network.php
src/Module/Conversation/Timeline.php
src/Module/Update/Network.php

index 12d8ae035e9f449d089568bc03969014bf8ded03..d32d9708c09e5e8efc9b90f1e8c94e45c2861224 100644 (file)
@@ -38,7 +38,6 @@ use Friendica\Core\L10n;
 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
 use Friendica\Core\Renderer;
 use Friendica\Core\Session\Capability\IHandleUserSessions;
-use Friendica\Model\Post;
 use Friendica\Module\Security\Login;
 use Friendica\Network\HTTPException;
 use Friendica\Database\Database;
@@ -160,13 +159,6 @@ class Channel extends Timeline
                        throw new HTTPException\BadRequestException($this->l10n->t('Channel not available.'));
                }
 
-               if (!empty($request['item'])) {
-                       $item          = Post::selectFirst(['parent-uri-id'], ['id' => $request['item']]);
-                       self::$item_id = $item['parent-uri-id'] ?? 0;
-               } else {
-                       self::$item_id = 0;
-               }
-
                self::$max_id = $request['last_created'] ?? self::$max_id;
        }
 }
index 9ab5f731e6138982be19fe839387a60dd0bcc09e..e5ec2bd659039cc2c9d141eface044d3c1f53ebf 100644 (file)
@@ -39,7 +39,6 @@ use Friendica\Core\L10n;
 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
 use Friendica\Core\Renderer;
 use Friendica\Core\Session\Capability\IHandleUserSessions;
-use Friendica\Model\Post;
 use Friendica\Network\HTTPException;
 use Friendica\Database\Database;
 use Friendica\Module\Response;
@@ -197,13 +196,6 @@ class Community extends Timeline
                        }
                }
 
-               if (!empty($request['item'])) {
-                       $item = Post::selectFirst(['parent'], ['id' => $request['item']]);
-                       self::$item_id = $item['parent'] ?? 0;
-               } else {
-                       self::$item_id = 0;
-               }
-
                self::$max_id = $request['last_commented'] ?? self::$max_id;
        }
 }
index b5b8a3d941431f539cdb24447cdd1b3249daf07c..cd24a7d77c5a9919e001eec9233a9a7dbe4ab50b 100644 (file)
@@ -418,37 +418,41 @@ class Network extends Timeline
                }
 
                // Currently only the order modes "received" and "commented" are in use
-               if (isset(self::$max_id)) {
-                       switch (self::$order) {
-                               case 'received':
-                                       $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` < ?", self::$max_id]);
-                                       break;
-                               case 'commented':
-                                       $conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` < ?", self::$max_id]);
-                                       break;
-                               case 'created':
-                                       $conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` < ?", self::$max_id]);
-                                       break;
-                               case 'uriid':
-                                       $conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` < ?", self::$max_id]);
-                                       break;
+               if (!empty(self::$item_uri_id)) {
+                       $conditionStrings = DBA::mergeConditions($conditionStrings, ['uri-id' => self::$item_uri_id]);
+               } else {
+                       if (isset(self::$max_id)) {
+                               switch (self::$order) {
+                                       case 'received':
+                                               $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` < ?", self::$max_id]);
+                                               break;
+                                       case 'commented':
+                                               $conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` < ?", self::$max_id]);
+                                               break;
+                                       case 'created':
+                                               $conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` < ?", self::$max_id]);
+                                               break;
+                                       case 'uriid':
+                                               $conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` < ?", self::$max_id]);
+                                               break;
+                               }
                        }
-               }
 
-               if (isset(self::$min_id)) {
-                       switch (self::$order) {
-                               case 'received':
-                                       $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` > ?", self::$min_id]);
-                                       break;
-                               case 'commented':
-                                       $conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` > ?", self::$min_id]);
-                                       break;
-                               case 'created':
-                                       $conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` > ?", self::$min_id]);
-                                       break;
-                               case 'uriid':
-                                       $conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` > ?", self::$min_id]);
-                                       break;
+                       if (isset(self::$min_id)) {
+                               switch (self::$order) {
+                                       case 'received':
+                                               $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` > ?", self::$min_id]);
+                                               break;
+                                       case 'commented':
+                                               $conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` > ?", self::$min_id]);
+                                               break;
+                                       case 'created':
+                                               $conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` > ?", self::$min_id]);
+                                               break;
+                                       case 'uriid':
+                                               $conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` > ?", self::$min_id]);
+                                               break;
+                               }
                        }
                }
 
index 49fcc062338c3c7ceaab356e52bb6dc08cc1e69d..881e974bd2379ac4287bbe3cd7b01938c80a515b 100644 (file)
@@ -36,6 +36,7 @@ use Friendica\Core\Session\Capability\IHandleUserSessions;
 use Friendica\Model\Contact;
 use Friendica\Model\User;
 use Friendica\Database\Database;
+use Friendica\Database\DBA;
 use Friendica\Model\Item;
 use Friendica\Model\Post;
 use Friendica\Module\Response;
@@ -58,6 +59,8 @@ class Timeline extends BaseModule
        /** @var int */
        protected static $item_id;
        /** @var int */
+       protected static $item_uri_id;
+       /** @var int */
        protected static $itemsPerPage;
        /** @var bool */
        protected static $no_sharer;
@@ -95,6 +98,7 @@ class Timeline extends BaseModule
         */
        protected function parseRequest(array $request)
        {
+               $this->logger->debug('Got request', $request);
                self::$selectedTab = $this->parameters['content'] ?? '';
 
                self::$accountTypeString = $request['accounttype'] ?? $this->parameters['accounttype'] ?? '';
@@ -116,6 +120,15 @@ class Timeline extends BaseModule
                        );
                }
 
+               if (!empty($request['item'])) {
+                       $item = Post::selectFirst(['parent', 'parent-uri-id'], ['id' => $request['item']]);
+                       self::$item_id     = $item['parent'] ?? 0;
+                       self::$item_uri_id = $item['parent-uri-id'] ?? 0;
+               } else {
+                       self::$item_id     = 0;
+                       self::$item_uri_id = 0;
+               }
+
                self::$min_id = $request['min_id'] ?? null;
                self::$max_id = $request['max_id'] ?? null;
 
@@ -219,33 +232,27 @@ class Timeline extends BaseModule
                        $condition = $this->addLanguageCondition($uid, $condition);
                }
 
-               $condition[0] .= " AND NOT EXISTS(SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `post-engagement`.`owner-id` AND (`ignored` OR `blocked` OR `collapsed`))";
-               $condition[] = $uid;
+               $condition = DBA::mergeConditions($condition, ["NOT EXISTS(SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `post-engagement`.`owner-id` AND (`ignored` OR `blocked` OR `collapsed`))", $uid]);
 
                if ((self::$selectedTab != TimelineEntity::WHATSHOT) && !is_null(self::$accountType)) {
-                       $condition[0] .= " AND `contact-type` = ?";
-                       $condition[] = self::$accountType;
+                       $condition = DBA::mergeConditions($condition, ['contact-type' => self::$accountType]);
                }
 
                $params = ['order' => ['created' => true], 'limit' => self::$itemsPerPage];
 
-               if (!empty(self::$item_id)) {
-                       $condition[0] .= " AND `uri-id` = ?";
-                       $condition[] = self::$item_id;
+               if (!empty(self::$item_uri_id)) {
+                       $condition = DBA::mergeConditions($condition, ['uri-id' => self::$item_uri_id]);
                } else {
                        if (self::$no_sharer) {
-                               $condition[0] .= " AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-engagement`.`uri-id`)";
-                               $condition[] = $uid;
+                               $condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-engagement`.`uri-id`)", $this->session->getLocalUserId()]);
                        }
 
                        if (isset(self::$max_id)) {
-                               $condition[0] .= " AND `created` < ?";
-                               $condition[] = self::$max_id;
+                               $condition = DBA::mergeConditions($condition, ["`created` < ?", self::$max_id]);
                        }
 
                        if (isset(self::$min_id)) {
-                               $condition[0] .= " AND `created` > ?";
-                               $condition[] = self::$min_id;
+                               $condition = DBA::mergeConditions($condition, ["`created` > ?", self::$min_id]);
 
                                // Previous page case: we want the items closest to min_id but for that we need to reverse the query order
                                if (!isset(self::$max_id)) {
@@ -260,7 +267,7 @@ class Timeline extends BaseModule
                }
 
                // Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order
-               if (empty(self::$item_id) && isset(self::$min_id) && !isset(self::$max_id)) {
+               if (empty(self::$item_uri_id) && isset(self::$min_id) && !isset(self::$max_id)) {
                        $items = array_reverse($items);
                }
 
@@ -433,23 +440,19 @@ class Timeline extends BaseModule
 
                $params = ['order' => ['commented' => true], 'limit' => self::$itemsPerPage];
 
-               if (!empty(self::$item_id)) {
-                       $condition[0] .= " AND `id` = ?";
-                       $condition[] = self::$item_id;
+               if (!empty(self::$item_uri_id)) {
+                       $condition = DBA::mergeConditions($condition, ['uri-id' => self::$item_uri_id]);
                } else {
                        if ($this->session->getLocalUserId() && self::$no_sharer) {
-                               $condition[0] .= " AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-thread-user-view`.`uri-id`)";
-                               $condition[] = $this->session->getLocalUserId();
+                               $condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-thread-user-view`.`uri-id`)", $this->session->getLocalUserId()]);
                        }
 
                        if (isset(self::$max_id)) {
-                               $condition[0] .= " AND `commented` < ?";
-                               $condition[] = self::$max_id;
+                               $condition = DBA::mergeConditions($condition, ["`commented` < ?", self::$max_id]);
                        }
 
                        if (isset(self::$min_id)) {
-                               $condition[0] .= " AND `commented` > ?";
-                               $condition[] = self::$min_id;
+                               $condition = DBA::mergeConditions($condition, ["`commented` > ?", self::$min_id]);
 
                                // Previous page case: we want the items closest to min_id but for that we need to reverse the query order
                                if (!isset(self::$max_id)) {
@@ -466,7 +469,7 @@ class Timeline extends BaseModule
                }
 
                // Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order
-               if (empty(self::$item_id) && isset(self::$min_id) && !isset(self::$max_id)) {
+               if (empty(self::$item_uri_id) && isset(self::$min_id) && !isset(self::$max_id)) {
                        $items = array_reverse($items);
                }
 
index bf33c6c053bbc05526282d66571d88afd7003be7..1a2ad17bac1777f26c71039d442a125860fd3c37 100644 (file)
@@ -65,8 +65,8 @@ class Network extends NetworkModule
                        $conditionFields['unseen'] = true;
                }
 
-               $params = ['limit' => 100];
-               $table = 'network-item-view';
+               $params = ['limit' => self::$itemsPerPage];
+               $table = 'network-thread-view';
 
                $items = $this->getItems($table, $params, $conditionFields);