]> git.mxchange.org Git - friendica.git/commitdiff
Some small performance tweaks
authorMichael <heluecht@pirati.ca>
Thu, 22 Jul 2021 15:35:30 +0000 (15:35 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 22 Jul 2021 15:35:30 +0000 (15:35 +0000)
mod/ping.php
src/Content/ForumManager.php
src/Model/Tag.php
src/Worker/ExpirePosts.php

index 8efddb757d5b671da4f24d316f498f2c5d5e4fdf..146e7e75b57de6519d86adb0da61c11c33ad05c9 100644 (file)
@@ -138,7 +138,7 @@ function ping_init(App $a)
 
                $condition = ["`unseen` AND `uid` = ? AND NOT `origin` AND (`vid` != ? OR `vid` IS NULL)",
                        local_user(), Verb::getID(Activity::FOLLOW)];
-               $items = Post::selectForUser(local_user(), ['wall', 'uid', 'uri-id'], $condition);
+               $items = Post::selectForUser(local_user(), ['wall', 'uid', 'uri-id'], $condition, ['limit' => 1000]);
                if (DBA::isResult($items)) {
                        $items_unseen = Post::toArray($items, false);
                        $arr = ['items' => $items_unseen];
@@ -253,8 +253,8 @@ function ping_init(App $a)
 
                $data['intro']    = $intro_count;
                $data['mail']     = $mail_count;
-               $data['net']      = $network_count;
-               $data['home']     = $home_count;
+               $data['net']      = ($network_count < 1000) ? $network_count : '999+';
+               $data['home']     = ($home_count < 1000) ? $home_count : '999+';
                $data['register'] = $register_count;
 
                $data['all-events']       = $all_events;
index 8556ba35303dd8591a6123b70233b770bc166fb8..4f416542013eb50d53833ac9cd0e31c74c9bada4 100644 (file)
@@ -215,8 +215,9 @@ class ForumManager
                                AND `contact`.`network` IN (?, ?) AND `contact`.`contact-type` = ?
                                AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
                                AND NOT `contact`.`pending` AND NOT `contact`.`archive`
+                               AND `contact`.`uid` = ?
                                GROUP BY `contact`.`id`",
-                       local_user(), Protocol::DFRN, Protocol::ACTIVITYPUB, Contact::TYPE_COMMUNITY
+                       local_user(), Protocol::DFRN, Protocol::ACTIVITYPUB, Contact::TYPE_COMMUNITY, local_user()
                );
 
                return DBA::toArray($stmtContacts);
index 1bc700c3f14f0215643db0cb899bcdcf430d33c6..ab7845c2c633ed623ace2e431c2408bc96b4ea4d 100644 (file)
@@ -545,13 +545,21 @@ class Tag
         */
        public static function setGlobalTrendingHashtags(int $period, int $limit = 10)
        {
+               // Get a uri-id that is at least X hours old.
+               // We use the uri-id in the query for the hash tags since this is much faster
+               $post = Post::selectFirstThread(['uri-id'], ["`uid` = ? AND `received` < UTC_TIMESTAMP() - INTERVAL ? HOUR", 0, $period],
+                       ['order' => ['received' => true]]);
+               if (empty($post['uri-id'])) {
+                       return [];
+               }
+
                $block_sql = self::getBlockedSQL();
 
                $tagsStmt = DBA::p("SELECT `name` AS `term`, COUNT(*) AS `score`, COUNT(DISTINCT(`author-id`)) as `authors`
                        FROM `tag-search-view`
-                       WHERE `private` = ? AND `uid` = ? AND `received` > DATE_SUB(NOW(), INTERVAL ? HOUR) $block_sql
+                       WHERE `private` = ? AND `uid` = ? AND `uri-id` > ? $block_sql
                        GROUP BY `term` ORDER BY `authors` DESC, `score` DESC LIMIT ?",
-                       Item::PUBLIC, 0, $period, $limit);
+                       Item::PUBLIC, 0, $post['uri-id'], $limit);
 
                if (DBA::isResult($tagsStmt)) {
                        $tags = DBA::toArray($tagsStmt);
@@ -590,13 +598,21 @@ class Tag
         */
        public static function setLocalTrendingHashtags(int $period, int $limit = 10)
        {
+               // Get a uri-id that is at least X hours old.
+               // We use the uri-id in the query for the hash tags since this is much faster
+               $post = Post::selectFirstThread(['uri-id'], ["`uid` = ? AND `received` < UTC_TIMESTAMP() - INTERVAL ? HOUR", 0, $period],
+                       ['order' => ['received' => true]]);
+               if (empty($post['uri-id'])) {
+                       return [];
+               }
+
                $block_sql = self::getBlockedSQL();
 
                $tagsStmt = DBA::p("SELECT `name` AS `term`, COUNT(*) AS `score`, COUNT(DISTINCT(`author-id`)) as `authors`
                        FROM `tag-search-view`
-                       WHERE `private` = ? AND `wall` AND `origin` AND `received` > DATE_SUB(NOW(), INTERVAL ? HOUR) $block_sql
+                       WHERE `private` = ? AND `wall` AND `origin` AND `uri-id` > ? $block_sql
                        GROUP BY `term` ORDER BY `authors` DESC, `score` DESC LIMIT ?",
-                       Item::PUBLIC, $period, $limit);
+                       Item::PUBLIC, $post['uri-id'], $limit);
 
                if (DBA::isResult($tagsStmt)) {
                        $tags = DBA::toArray($tagsStmt);
index de650f667d93156b332c56c3048e0b24e45c22fe..bd1addf11a469e1e03243dface2ff5167bf0e290 100644 (file)
@@ -170,7 +170,7 @@ class ExpirePosts
        {
                // We have to avoid deleting newly created "item-uri" entries.
                // So we fetch a post that had been stored yesterday and only delete older ones.
-               $item = Post::selectFirst(['uri-id'], ["`uid` = ? AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY", 0, 1],
+               $item = Post::selectFirstThread(['uri-id'], ["`uid` = ? AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY", 0, 1],
                        ['order' => ['received' => true]]);
                if (empty($item['uri-id'])) {
                        Logger::warning('No item with uri-id found - we better quit here');