Skip to content

Commit 16e915d

Browse files
committed
Total user count should return a count for all wikis including deleted wikis
1 parent ab13e22 commit 16e915d

2 files changed

Lines changed: 1 addition & 73 deletions

File tree

app/Metrics/App/WikiMetrics.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function saveMetrics(Wiki $wiki): void {
3636
$quarterlyActions = $this->getNumberOfActions(self::INTERVAL_QUARTERLY);
3737
$numberOfEntities = $this->getNumberOfEntities();
3838
$monthlyNumberOfUsersPerActivityType = $this->getNumberOfUsersPerActivityType();
39-
$numberOfUsersPerWiki = $this->getTotalUserCount();
39+
$numberOfUsersPerWiki = $wiki->wikiSiteStats()->first()->users ?? 0;
4040

4141
$dailyMetrics = new WikiDailyMetrics([
4242
'id' => $wiki->id . '_' . date('Y-m-d'),
@@ -212,17 +212,4 @@ private function getNumberOfEntities(): array {
212212

213213
return $result;
214214
}
215-
216-
private function getTotalUserCount() {
217-
$wikiDb = $this->wiki->wikiDb;
218-
$tableUser = "{$wikiDb->name}.{$wikiDb->prefix}_user";
219-
$query = "SELECT COUNT(*) AS total_users FROM $tableUser";
220-
$manager = app()->db;
221-
$manager->purge('mw');
222-
$conn = $manager->connection('mw');
223-
$pdo = $conn->getPdo();
224-
$result = $pdo->query($query)->fetch(PDO::FETCH_ASSOC);
225-
226-
return $result['total_users'] ?? null;
227-
}
228215
}

tests/Metrics/WikiMetricsTest.php

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -363,63 +363,4 @@ public function testSavesEntityCountsCorrectly($expectedItemCount, $expectedProp
363363
'entity_schema_count' => $expectedEntitySchemaCount, // redirects should be ignored
364364
]);
365365
}
366-
367-
public function testSavesTotalUserCountCorrectly() {
368-
$wiki = Wiki::factory()->create([
369-
'domain' => 'usercounttest.wikibase.cloud',
370-
]);
371-
372-
$users = [
373-
[
374-
'user_name' => 'user1',
375-
'user_real_name' => 'user1',
376-
'user_password' => 'user1',
377-
'user_new_password' => 'user1',
378-
'user_email' => 'user1@email.com',
379-
'user_touched' => random_bytes(10),
380-
],
381-
[
382-
'user_name' => 'user2',
383-
'user_real_name' => 'user2',
384-
'user_password' => 'user2',
385-
'user_new_password' => 'user2',
386-
'user_email' => 'user2@email.com',
387-
'user_touched' => random_bytes(10),
388-
],
389-
];
390-
$wikiDb = WikiDb::first();
391-
$wikiDb->update(['wiki_id' => $wiki->id]);
392-
393-
$tableUser = $wikiDb->name . '.' . $wikiDb->prefix . '_user';
394-
Schema::dropIfExists($tableUser);
395-
Schema::create($tableUser, function (Blueprint $table) {
396-
$table->increments('user_id');
397-
$table->string('user_name');
398-
$table->string('user_real_name')->default(0);
399-
$table->string('user_password', 255);
400-
$table->string('user_new_password');
401-
$table->string('user_email');
402-
$table->binary('user_touched');
403-
});
404-
405-
// Insert dummy data
406-
DB::table($tableUser)->insert($users);
407-
WikiDailyMetrics::create([
408-
'id' => $wiki->id . '_' . now()->subDay()->toDateString(),
409-
'wiki_id' => $wiki->id,
410-
'date' => now()->subDay()->toDateString(),
411-
'pages' => 0,
412-
'is_deleted' => 0,
413-
]);
414-
415-
(new WikiMetrics)->saveMetrics($wiki);
416-
417-
// clean up after the test
418-
$wiki->forceDelete();
419-
420-
$this->assertDatabaseHas('wiki_daily_metrics', [
421-
'wiki_id' => $wiki->id,
422-
'total_user_count' => count($users),
423-
]);
424-
}
425366
}

0 commit comments

Comments
 (0)