]> git.mxchange.org Git - friendica.git/commitdiff
Set posts "seen" by a worker if too much rows are unseen
authorMichael <heluecht@pirati.ca>
Sun, 23 Jun 2024 21:24:19 +0000 (21:24 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 23 Jun 2024 21:33:25 +0000 (21:33 +0000)
src/Module/Conversation/Network.php
src/Worker/SetSeen.php [new file with mode: 0644]

index da3054b1f506fe2e6792c40b8ad8b90b127d4692..6bd342e19c5421b981b8e469abb6461b509bd427 100644 (file)
@@ -47,10 +47,12 @@ use Friendica\Core\L10n;
 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
 use Friendica\Core\Renderer;
 use Friendica\Core\Session\Capability\IHandleUserSessions;
+use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Database\Database;
 use Friendica\Model\Contact;
 use Friendica\Model\Circle;
+use Friendica\Model\Post;
 use Friendica\Model\Profile;
 use Friendica\Module\Response;
 use Friendica\Module\Security\Login;
@@ -231,7 +233,7 @@ class Network extends Timeline
                        } else {
                                $items = $this->getItems();
                        }
-       
+
                        $o .= $this->conversation->render($items, Conversation::MODE_NETWORK, false, false, $this->getOrder(), $this->session->getLocalUserId());
                } catch (\Exception $e) {
                        $o .= $this->l10n->t('Error %d (%s) while fetching the timeline.', $e->getCode(), $e->getMessage());
@@ -470,23 +472,20 @@ class Network extends Timeline
                        $items = array_reverse($items);
                }
 
-               if ($this->database->isResult($items)) {
-                       $parents = array_column($items, 'uri-id');
-               } else {
-                       $parents = [];
+               if ($this->ping || !$this->database->isResult($items)) {
+                       return $items;
                }
 
-               // We aren't going to try and figure out at the item, circle, and page
-               // level which items you've seen and which you haven't. If you're looking
-               // at the top level network page just mark everything seen.
-               if (!$this->circleId && !$this->star && !$this->mention) {
-                       $condition = ['unseen' => true, 'uid' => $this->session->getLocalUserId()];
-                       $this->setItemsSeenByCondition($condition);
-               } elseif (!empty($parents)) {
-                       $condition = ['unseen' => true, 'uid' => $this->session->getLocalUserId(), 'parent-uri-id' => $parents];
-                       $this->setItemsSeenByCondition($condition);
+               $this->setItemsSeenByCondition(['unseen' => true, 'uid' => $this->session->getLocalUserId(), 'parent-uri-id' => array_column($items, 'uri-id')]);
+
+               $posts = Post::selectToArray(['uri-id'], ['unseen' => true, 'uid' => $this->session->getLocalUserId()], ['limit' => 100]);
+               if (!empty($posts)) {
+                       $this->setItemsSeenByCondition(['unseen' => true, 'uid' => $this->session->getLocalUserId(), 'uri-id' => array_column($posts, 'uri-id')]);
                }
 
+               if (count($posts) == 100) {
+                       Worker::add(Worker::PRIORITY_MEDIUM, 'SetSeen', $this->session->getLocalUserId());
+               }
                return $items;
        }
 
diff --git a/src/Worker/SetSeen.php b/src/Worker/SetSeen.php
new file mode 100644 (file)
index 0000000..3091e4e
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2024, the Friendica project
+ *
+ * @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\Worker;
+
+use Friendica\Core\Logger;
+use Friendica\Model\Item;
+
+/**
+ * Set posts seen for the given user.
+ */
+class SetSeen
+{
+       public static function execute(int $uid)
+       {
+               $ret = Item::update(['unseen' => false], ['unseen' => true, 'uid' => $uid]);
+               Logger::debug('Set seen', ['uid' => $uid, 'ret' => $ret]);
+       }
+}