]> git.mxchange.org Git - friendica.git/commitdiff
More statistics variables added
authorMichael <heluecht@pirati.ca>
Mon, 22 Jul 2024 21:21:23 +0000 (21:21 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 22 Jul 2024 21:47:25 +0000 (21:47 +0000)
src/Model/Item.php
src/Model/Nodeinfo.php
src/Module/Stats.php

index bdc18fd6bde19f809af79ee3788c73c5020f496d..72bf396bf370fb1ed43c26c305c0d9f14be61a0a 100644 (file)
@@ -419,6 +419,14 @@ class Item
                        self::markForDeletion(['parent' => $item['parent'], 'deleted' => false], $priority);
                }
 
+               if ($item['uid'] == 0 && $item['gravity'] == self::GRAVITY_PARENT) {
+                       $posts = DI::keyValue()->get('nodeinfo_total_posts') ?? 0;
+                       DI::keyValue()->set('nodeinfo_total_posts', $posts - 1);
+               } elseif ($item['uid'] == 0 && $item['gravity'] == self::GRAVITY_COMMENT) {
+                       $comments = DI::keyValue()->get('nodeinfo_total_comments') ?? 0;
+                       DI::keyValue()->set('nodeinfo_total_comments', $comments - 1);
+               }
+
                // Is it our comment and/or our thread?
                if (($item['origin'] || $parent['origin']) && ($item['uid'] != 0)) {
                        if ($item['origin'] && $item['gravity'] == self::GRAVITY_PARENT) {
@@ -428,7 +436,7 @@ class Item
                                $comments = DI::keyValue()->get('nodeinfo_local_comments') ?? 0;
                                DI::keyValue()->set('nodeinfo_local_comments', $comments - 1);
                        }
-       
+
                        // When we delete the original post we will delete all existing copies on the server as well
                        self::markForDeletion(['uri-id' => $item['uri-id'], 'deleted' => false], $priority);
 
@@ -1455,6 +1463,14 @@ class Item
                }
 
                if ($inserted) {
+                       if ($posted_item['gravity'] == self::GRAVITY_PARENT) {
+                               $posts = DI::keyValue()->get('nodeinfo_total_posts') ?? 0;
+                               DI::keyValue()->set('nodeinfo_total_posts', $posts + 1);
+                       } elseif ($posted_item['gravity'] == self::GRAVITY_COMMENT) {
+                               $comments = DI::keyValue()->get('nodeinfo_total_comments') ?? 0;
+                               DI::keyValue()->set('nodeinfo_total_comments', $comments + 1);
+                       }
+
                        // Fill the cache with the rendered content.
                        if (in_array($posted_item['gravity'], [self::GRAVITY_PARENT, self::GRAVITY_COMMENT])) {
                                self::updateDisplayCache($posted_item['uri-id']);
index 7df5591f8e12f78bfcdc823fa2471b4ea87ab128..bda8583c4dcea30b7cef27ab4e6566221564c29b 100644 (file)
@@ -69,6 +69,11 @@ class Nodeinfo
                DI::keyValue()->set('nodeinfo_local_posts', $posts);
                DI::keyValue()->set('nodeinfo_local_comments', $comments);
 
+               $posts = DBA::count('post', ['deleted' => false, 'gravity' => Item::GRAVITY_COMMENT]);
+               $comments = DBA::count('post', ['deleted' => false, 'gravity' => Item::GRAVITY_COMMENT]);
+               DI::keyValue()->set('nodeinfo_total_posts', $posts);
+               DI::keyValue()->set('nodeinfo_total_comments', $comments);
+
                $logger->info('Post statistics - done', ['posts' => $posts, 'comments' => $comments]);
        }
 
@@ -76,7 +81,7 @@ class Nodeinfo
         * Return the supported services
         *
         * @return Object with supported services
-       */
+        */
        public static function getUsage(bool $version2 = false)
        {
                $config = DI::config();
@@ -103,7 +108,7 @@ class Nodeinfo
         * Return the supported services
         *
         * @return array with supported services
-       */
+        */
        public static function getServices(): array
        {
                $services = [
index bc0a44fb199125be5a3c9521d0a8fc0d760a796b..b5afb9a13a0629adaed3e998c4041e6be7237098 100644 (file)
@@ -28,6 +28,8 @@ use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs;
 use Friendica\Core\L10n;
 use Friendica\Core\Worker;
 use Friendica\Database\Database;
+use Friendica\Model\Register;
+use Friendica\Moderation\Entity\Report;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Profiler;
 use Psr\Log\LoggerInterface;
@@ -67,7 +69,22 @@ class Stats extends BaseModule
                        return;
                }
 
+               $report = $this->dba->selectFirst('report', ['created'], [], ['order' => ['created' => true]]);
+               if (!empty($report)) {
+                       $report_datetime  = DateTimeFormat::utc($report['created'], DateTimeFormat::JSON);
+                       $report_timestamp = strtotime($report['created']);
+               } else {
+                       $report_datetime  = '';
+                       $report_timestamp = 0;
+               }
+
                $statistics = [
+                       'cron' => [
+                               'lastExecution' => [
+                                       'datetime'  => DateTimeFormat::utc($this->keyValue->get('last_cron'), DateTimeFormat::JSON),
+                                       'timestamp' => (int)$this->keyValue->get('last_cron'),
+                               ],
+                       ],
                        'worker' => [
                                'lastExecution' => [
                                        'datetime'  => DateTimeFormat::utc($this->keyValue->get('last_worker_execution'), DateTimeFormat::JSON),
@@ -84,14 +101,29 @@ class Stats extends BaseModule
                        ],
                        'users' => [
                                'total'          => intval($this->keyValue->get('nodeinfo_total_users')),
-                               'activeHalfyear' => intval($this->keyValue->get('nodeinfo_active_users_halfyear')),
-                               'activeMonth'    => intval($this->keyValue->get('nodeinfo_active_users_monthly')),
                                'activeWeek'     => intval($this->keyValue->get('nodeinfo_active_users_weekly')),
+                               'activeMonth'    => intval($this->keyValue->get('nodeinfo_active_users_monthly')),
+                               'activeHalfyear' => intval($this->keyValue->get('nodeinfo_active_users_halfyear')),
+                               'pending'        => Register::getPendingCount(),
                        ],
-                       'usage' => [
-                               'localPosts'    => intval($this->keyValue->get('nodeinfo_local_posts')),
-                               'localComments' => intval($this->keyValue->get('nodeinfo_local_comments')),
+                       'posts' => [
+                               'inbound' => [
+                                       'posts'    => intval($this->keyValue->get('nodeinfo_total_posts')) - intval($this->keyValue->get('nodeinfo_local_posts')),
+                                       'comments' => intval($this->keyValue->get('nodeinfo_total_comments')) - intval($this->keyValue->get('nodeinfo_local_comments')),
+                               ],
+                               'outbound' => [
+                                       'posts'    => intval($this->keyValue->get('nodeinfo_local_posts')),
+                                       'comments' => intval($this->keyValue->get('nodeinfo_local_comments')),
+                               ],
                        ],
+                       'reports' => [
+                               'newest' => [
+                                       'datetime'  => $report_datetime,
+                                       'timestamp' => $report_timestamp,
+                               ],
+                               'open'   => $this->dba->count('report', ['status' => Report::STATUS_OPEN]),
+                               'closed' => $this->dba->count('report', ['status' => Report::STATUS_CLOSED]),
+                       ]
                ];
 
                $statistics = $this->getJobsPerPriority($statistics);