]> git.mxchange.org Git - friendica.git/commitdiff
The item count is now done in a single query
authorMichael <heluecht@pirati.ca>
Sat, 11 Jan 2020 14:25:43 +0000 (14:25 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 11 Jan 2020 14:25:43 +0000 (14:25 +0000)
src/Model/Nodeinfo.php

index 6d9c77154a17b720c570f3ab04663c05e39b7b94..7cde259538c95b26ced1c3f0ffe3b8bc832305bc 100644 (file)
@@ -52,12 +52,15 @@ class Nodeinfo
 
                $logger->debug('user statistics', $userStats);
 
-               $local_posts = DBA::count('thread', ["`wall` AND NOT `deleted` AND `uid` != 0"]);
-               $config->set('nodeinfo', 'local_posts', $local_posts);
-               $logger->debug('thread statistics', ['local_posts' => $local_posts]);
-
-               $local_comments = DBA::count('item', ["`origin` AND `id` != `parent` AND NOT `deleted` AND `uid` != 0"]);
-               $config->set('nodeinfo', 'local_comments', $local_comments);
-               $logger->debug('item statistics', ['local_comments' => $local_comments]);
+               $items = DBA::p("SELECT COUNT(*) AS `total`, `gravity` FROM `item` WHERE `origin` AND NOT `deleted` AND `uid` != 0 AND `gravity` IN (?, ?) GROUP BY `gravity`",
+                       GRAVITY_PARENT, GRAVITY_COMMENT);
+               while ($item = DBA::fetch($items)) {
+                       if ($item['gravity'] == GRAVITY_PARENT) {
+                               $config->set('nodeinfo', 'local_posts', $item['total']);
+                       } elseif ($item['gravity'] == GRAVITY_COMMENT) {
+                               $config->set('nodeinfo', 'local_comments', $item['total']);
+                       }
+               }
+               DBA::close($items);
        }
 }