Serve dashboard stats from daily_stats and default visit list to today.
Stop live-scanning page_visits on every dashboard load (including today) so the admin home stays fast; keep the live path only for channel filters and cache the result for 45s. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -698,4 +698,48 @@ class PageVisitTest extends TestCase
|
||||
->assertJsonPath('data.1.stage', 'pe')
|
||||
->assertJsonPath('data.1.stage_label', '权限提升');
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function visits_data_defaults_to_today(): void
|
||||
{
|
||||
PageVisit::query()->create([
|
||||
'channel_id' => self::CHANNEL,
|
||||
'client_uid' => 'today-uid',
|
||||
'os' => 'iOS',
|
||||
'os_version' => '16.6',
|
||||
'browser' => 'Safari',
|
||||
'created_at' => now(),
|
||||
]);
|
||||
PageVisit::query()->create([
|
||||
'channel_id' => self::CHANNEL,
|
||||
'client_uid' => 'old-uid',
|
||||
'os' => 'iOS',
|
||||
'os_version' => '16.6',
|
||||
'browser' => 'Safari',
|
||||
'created_at' => now()->subDays(2),
|
||||
]);
|
||||
|
||||
$admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']);
|
||||
$payload = $this->actingAs($admin, 'admin')
|
||||
->getJson(route('admin.visits.data'))
|
||||
->assertOk()
|
||||
->assertJsonPath('code', 0)
|
||||
->assertJsonPath('count', 1)
|
||||
->json('data');
|
||||
|
||||
$this->assertCount(1, $payload);
|
||||
$this->assertSame('today-uid', $payload[0]['client_uid']);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function visits_page_defaults_range_to_today(): void
|
||||
{
|
||||
$admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']);
|
||||
$this->actingAs($admin, 'admin')
|
||||
->get(route('admin.visits.index'))
|
||||
->assertOk()
|
||||
->assertSee('value="today" selected', false)
|
||||
->assertSee("range: 'today'", false)
|
||||
->assertDontSee("range: '30d'", false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user