From ed71baaab3da87dd61f9b8116898afeb84e64e64 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 12 Sep 2026 17:12:29 +0930 Subject: [PATCH] Add notification epoch inline fallback test (#7162) getEpochId() now computes a bounded epoch inline on cache miss (oldest notification within the window) instead of returning 1, which would turn every notification query into a full-table scan until the async pipeline repopulates the cache. Adds coverage for the recent-id fallback and the no-recent-notifications case. (Code change committed alongside the #7195 NotificationService edits.) --- .../NotificationEpochFallbackTest.php | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/Feature/Services/NotificationEpochFallbackTest.php diff --git a/tests/Feature/Services/NotificationEpochFallbackTest.php b/tests/Feature/Services/NotificationEpochFallbackTest.php new file mode 100644 index 000000000..8ccc41751 --- /dev/null +++ b/tests/Feature/Services/NotificationEpochFallbackTest.php @@ -0,0 +1,62 @@ + 1`, scanning the +| entire notifications table. +| +*/ + +beforeEach(function () { + Queue::fake(); + Cache::forget(NotificationService::EPOCH_CACHE_KEY.'6'); +}); + +it('returns a recent notification id on cache miss instead of 1', function () { + $old = Notification::create([ + 'profile_id' => 1, + 'actor_id' => 2, + 'action' => 'like', + 'created_at' => now()->subMonths(9), + ]); + + $recent = Notification::create([ + 'profile_id' => 1, + 'actor_id' => 2, + 'action' => 'like', + 'created_at' => now()->subMonth(), + ]); + + $epoch = NotificationService::getEpochId(); + + expect($epoch)->toBe($recent->id); + expect($epoch)->not->toBe(1); + expect($epoch)->toBeGreaterThan($old->id); + + Queue::assertPushed(NotificationEpochUpdatePipeline::class); +}); + +it('falls back to 1 when no recent notifications exist', function () { + Notification::create([ + 'profile_id' => 1, + 'actor_id' => 2, + 'action' => 'like', + 'created_at' => now()->subYear(), + ]); + + expect(NotificationService::getEpochId())->toBe(1); +});