Merge pull request #14317 from annando/stats2

More statistics variables added
This commit is contained in:
Tobias Diekershoff 2024-07-23 07:24:56 +02:00 committed by GitHub
commit ca5f93a4d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 61 additions and 8 deletions

View 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) {
@ -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']);

View 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]);
}

View 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);