]> git.mxchange.org Git - friendica.git/commitdiff
Nodeinfo data has moved to key values
authorMichael <heluecht@pirati.ca>
Wed, 18 Jan 2023 05:04:37 +0000 (05:04 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 18 Jan 2023 05:04:37 +0000 (05:04 +0000)
database.sql
src/Model/Nodeinfo.php
src/Module/Statistics.php
src/Object/Api/Mastodon/Stats.php
static/dbstructure.config.php
update.php

index 48e0930e67bcac89503f56c9f79fc2d16811ea8a..0b91aedc06112d42ffc37024826bde562998d182 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2023.03-dev (Giant Rhubarb)
--- DB_UPDATE_VERSION 1511
+-- DB_UPDATE_VERSION 1512
 -- ------------------------------------------
 
 
index 0fbaf93c7e703e67ab1124b77b6140e0ee99b7b6..07f56dd7bb83970464a0f9f738f242e57722cd1a 100644 (file)
@@ -55,17 +55,17 @@ class Nodeinfo
 
                $userStats = User::getStatistics();
 
-               $config->set('nodeinfo', 'total_users', $userStats['total_users']);
-               $config->set('nodeinfo', 'active_users_halfyear', $userStats['active_users_halfyear']);
-               $config->set('nodeinfo', 'active_users_monthly', $userStats['active_users_monthly']);
-               $config->set('nodeinfo', 'active_users_weekly', $userStats['active_users_weekly']);
+               DI::keyValue()->set('nodeinfo_total_users', $userStats['total_users']);
+               DI::keyValue()->set('nodeinfo_active_users_halfyear', $userStats['active_users_halfyear']);
+               DI::keyValue()->set('nodeinfo_active_users_monthly', $userStats['active_users_monthly']);
+               DI::keyValue()->set('nodeinfo_active_users_weekly', $userStats['active_users_weekly']);
 
                $logger->info('user statistics', $userStats);
 
                $posts = DBA::count('post-thread', ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE NOT `deleted` AND `origin`)"]);
                $comments = DBA::count('post', ["NOT `deleted` AND `gravity` = ? AND `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)", Item::GRAVITY_COMMENT]);
-               $config->set('nodeinfo', 'local_posts', $posts);
-               $config->set('nodeinfo', 'local_comments', $comments);
+               DI::keyValue()->set('nodeinfo_local_posts', $posts);
+               DI::keyValue()->set('nodeinfo_local_comments', $comments);
 
                $logger->info('User actitivy', ['posts' => $posts, 'comments' => $comments]);
        }
@@ -83,14 +83,14 @@ class Nodeinfo
                $usage->users = new \stdClass;
 
                if (!empty($config->get('system', 'nodeinfo'))) {
-                       $usage->users->total = intval($config->get('nodeinfo', 'total_users'));
-                       $usage->users->activeHalfyear = intval($config->get('nodeinfo', 'active_users_halfyear'));
-                       $usage->users->activeMonth = intval($config->get('nodeinfo', 'active_users_monthly'));
-                       $usage->localPosts = intval($config->get('nodeinfo', 'local_posts'));
-                       $usage->localComments = intval($config->get('nodeinfo', 'local_comments'));
+                       $usage->users->total = intval(DI::keyValue()->get('nodeinfo_total_users'));
+                       $usage->users->activeHalfyear = intval(DI::keyValue()->get('nodeinfo_active_users_halfyear'));
+                       $usage->users->activeMonth = intval(DI::keyValue()->get('nodeinfo_active_users_monthly'));
+                       $usage->localPosts = intval(DI::keyValue()->get('nodeinfo_local_posts'));
+                       $usage->localComments = intval(DI::keyValue()->get('nodeinfo_local_comments'));
 
                        if ($version2) {
-                               $usage->users->activeWeek = intval($config->get('nodeinfo', 'active_users_weekly'));
+                               $usage->users->activeWeek = intval(DI::keyValue()->get('nodeinfo_active_users_weekly'));
                        }
                }
 
index 75d3e6432b17f76620607ce0322be17054aa7e06..514f10bb73d768d836fb576d06d29a5c6863b2d0 100644 (file)
@@ -25,6 +25,7 @@ use Friendica\App;
 use Friendica\BaseModule;
 use Friendica\Core\Addon;
 use Friendica\Core\Config\Capability\IManageConfigValues;
+use Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Network\HTTPException\NotFoundException;
@@ -35,13 +36,15 @@ class Statistics extends BaseModule
 {
        /** @var IManageConfigValues */
        protected $config;
-
-       public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManageConfigValues $config, Response $response, array $server, array $parameters = [])
+       /** @var IManageKeyValuePairs */
+       protected $keyValue;
+       
+       public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManageConfigValues $config, IManageKeyValuePairs $keyValue, Response $response, array $server, array $parameters = [])
        {
                parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
 
-               $this->config = $config;
-
+               $this->config   = $config;
+               $this->keyValue = $keyValue;
                if (!$this->config->get("system", "nodeinfo")) {
                        throw new NotFoundException();
                }
@@ -72,10 +75,10 @@ class Statistics extends BaseModule
                        'network'               => App::PLATFORM,
                        'version'               => App::VERSION . '-' . DB_UPDATE_VERSION,
                        'registrations_open'    => $registration_open,
-                       'total_users'           => $this->config->get('nodeinfo', 'total_users'),
-                       'active_users_halfyear' => $this->config->get('nodeinfo', 'active_users_halfyear'),
-                       'active_users_monthly'  => $this->config->get('nodeinfo', 'active_users_monthly'),
-                       'local_posts'           => $this->config->get('nodeinfo', 'local_posts'),
+                       'total_users'           => $this->keyValue->get('nodeinfo_total_users'),
+                       'active_users_halfyear' => $this->keyValue->get('nodeinfo_active_users_halfyear'),
+                       'active_users_monthly'  => $this->keyValue->get('nodeinfo_active_users_monthly'),
+                       'local_posts'           => $this->keyValue->get('nodeinfo_local_posts'),
                        'services'              => $services,
                ], $services);
 
index 1f08ab2ed79dca30a74455c7a62a5737226e4870..335c82d43176f3f23756b66651cd09f11f218e8f 100644 (file)
@@ -25,7 +25,6 @@ use Friendica\BaseDataTransferObject;
 use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\Core\Protocol;
 use Friendica\Database\Database;
-use Friendica\Database\DBA;
 use Friendica\DI;
 
 /**
@@ -45,9 +44,9 @@ class Stats extends BaseDataTransferObject
        public function __construct(IManageConfigValues $config, Database $database)
        {
                if (!empty($config->get('system', 'nodeinfo'))) {
-                       $this->user_count   = intval($config->get('nodeinfo', 'total_users'));
-                       $this->status_count = $config->get('nodeinfo', 'local_posts') + $config->get('nodeinfo', 'local_comments');
-                       $this->domain_count = $database->count('gserver', ["`network` in (?, ?) AND NOT `failed`", Protocol::DFRN, Protocol::ACTIVITYPUB]);
+                       $this->user_count   = intval(DI::keyValue()->get('nodeinfo_total_users'));
+                       $this->status_count = DI::keyValue()->get('nodeinfo_local_posts') + DI::keyValue()->get('nodeinfo_local_comments');
+                       $this->domain_count = $database->count('gserver', ["`network` in (?, ?) AND NOT `failed` AND NOT `blocked`", Protocol::DFRN, Protocol::ACTIVITYPUB]);
                }
        }
 }
index a6459f16ba6f507a1f78fb5c37c2492393ce69f4..4329410b4ac9234fb9d724a5fd246785aaded5db 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1511);
+       define('DB_UPDATE_VERSION', 1512);
 }
 
 return [
index 85a06892f04c99a542545221ceba5bdfa4f0ad07..8f937752599535f34bd58d941ca5e2c4a231a751 100644 (file)
@@ -1227,3 +1227,20 @@ function update_1510()
        }
        return Update::SUCCESS;
 }
+
+function update_1512()
+{
+       DI::keyValue()->set('nodeinfo_total_users', DI::config()->get('nodeinfo', 'total_users'));
+       DI::keyValue()->set('nodeinfo_active_users_halfyear', DI::config()->get('nodeinfo', 'active_users_halfyear'));
+       DI::keyValue()->set('nodeinfo_active_users_monthly', DI::config()->get('nodeinfo', 'active_users_monthly'));
+       DI::keyValue()->set('nodeinfo_active_users_weekly', DI::config()->get('nodeinfo', 'active_users_weekly'));
+       DI::keyValue()->set('nodeinfo_local_posts', DI::config()->get('nodeinfo', 'local_posts'));
+       DI::keyValue()->set('nodeinfo_local_comments', DI::config()->get('nodeinfo', 'local_comments'));
+
+       DI::config()->delete('nodeinfo', 'total_users');
+       DI::config()->delete('nodeinfo', 'active_users_halfyear');
+       DI::config()->delete('nodeinfo', 'active_users_monthly');
+       DI::config()->delete('nodeinfo', 'active_users_weekly');
+       DI::config()->delete('nodeinfo', 'local_posts');
+       DI::config()->delete('nodeinfo', 'local_comments');
+}