Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/Metrics/App/WikiMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function saveMetrics(Wiki $wiki): void {
$monthlyActions = $this->getNumberOfActions(self::INTERVAL_MONTHLY);
$quarterlyActions = $this->getNumberOfActions(self::INTERVAL_QUARTERLY);
$numberOfEntities = $this->getNumberOfEntities();
$totalNumberOfUsers = $this->getTotalUserCount();
$monthlyNumberOfUsersPerActivityType = $this->getNumberOfUsersPerActivityType();

$dailyMetrics = new WikiDailyMetrics([
Expand All @@ -54,6 +55,7 @@ public function saveMetrics(Wiki $wiki): void {
'entity_schema_count' => $numberOfEntities['640'],
'monthly_casual_users' => $monthlyNumberOfUsersPerActivityType[0],
'monthly_active_users' => $monthlyNumberOfUsersPerActivityType[1],
'wiki_user_count' => $totalNumberOfUsers,
]);

// compare current record to old record and only save if there is a change
Expand Down Expand Up @@ -210,4 +212,16 @@ private function getNumberOfEntities(): array {

return $result;
}

private function getTotalUserCount() {
$wikiDb = $this->wiki->wikiDb;
$tableUser = $wikiDb->name . '.' . $wikiDb->prefix . '_user';
$query = "SELECT COUNT(*) AS total_users FROM $tableUser";
$manager = app()->db;
$manager->purge('mw');
$conn = $manager->connection('mw');
$pdo = $conn->getPdo();
$result = $pdo->query($query)->fetchAll(PDO::FETCH_ASSOC);
return $result['total_users'];
}
}
2 changes: 2 additions & 0 deletions app/WikiDailyMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class WikiDailyMetrics extends Model {
'entity_schema_count',
'monthly_casual_users',
'monthly_active_users',
'wiki_user_count',

];

Expand All @@ -51,6 +52,7 @@ class WikiDailyMetrics extends Model {
'entity_schema_count',
'monthly_casual_users',
'monthly_active_users',
'wiki_user_count',
];

public function areMetricsEqual(WikiDailyMetrics $wikiDailyMetrics): bool {
Expand Down
28 changes: 28 additions & 0 deletions database/migrations/2025_10_16_055552_add_total_user_count.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('wiki_daily_metrics', function (Blueprint $table) {
$table->integer('total_user_count')->nullable()->default(null);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('wiki_daily_metrics', function (Blueprint $table) {
$table->dropColumn('total_user_count');
});
}
};
2 changes: 2 additions & 0 deletions tests/Jobs/UpdateWikiDailyMetricJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function testRunJobForAllWikisIncludingDeletedWikis() {
'property_count' => 0,
'lexeme_count' => 0,
'entity_schema_count' => 0,
'wiki_user_count' => 0,
]);

$this->assertDatabaseHas('wiki_daily_metrics', [
Expand All @@ -70,6 +71,7 @@ public function testRunJobForAllWikisIncludingDeletedWikis() {
'property_count' => 0,
'lexeme_count' => 0,
'entity_schema_count' => 0,
'wiki_user_count' => 0,
]);
}
}
Loading