From 652ebb956dc9d7c1e77c675bdbd524ce976681ad Mon Sep 17 00:00:00 2001 From: alwood Date: Sat, 17 Jan 2026 17:43:17 +0100 Subject: [PATCH] fix: async changelog prefetch chore: poll changelog sooner chore: cap changelog polling --- app/Livewire/SettingsDropdown.php | 53 +++++++++++++++++++ .../livewire/settings-dropdown.blade.php | 8 ++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/app/Livewire/SettingsDropdown.php b/app/Livewire/SettingsDropdown.php index 7afa763df..a6db9f04f 100644 --- a/app/Livewire/SettingsDropdown.php +++ b/app/Livewire/SettingsDropdown.php @@ -11,6 +11,12 @@ class SettingsDropdown extends Component { public $showWhatsNewModal = false; + public bool $shouldPollChangelog = false; + + public bool $changelogFetchRequested = false; + + public int $changelogPollAttempts = 0; + public function getUnreadCountProperty() { return Auth::user()->getUnreadChangelogCount(); @@ -31,6 +37,53 @@ class SettingsDropdown extends Component public function openWhatsNewModal() { $this->showWhatsNewModal = true; + + $this->prefetchChangelog(); + } + + public function prefetchChangelog() + { + $entries = app(ChangelogService::class)->getEntriesForUser(Auth::user()); + if ($entries->isEmpty()) { + if (! $this->changelogFetchRequested) { + $this->changelogFetchRequested = true; + $this->shouldPollChangelog = true; + $this->changelogPollAttempts = 0; + PullChangelog::dispatch(); + } + + return; + } + + $this->dispatch('changelog-entries', entries: $entries->values()->all()); + } + + public function refreshChangelog() + { + if (! $this->shouldPollChangelog) { + return; + } + + $this->changelogPollAttempts++; + if ($this->changelogPollAttempts > 10) { + $this->shouldPollChangelog = false; + $this->changelogFetchRequested = false; + + return; + } + + $entries = app(ChangelogService::class)->getEntriesForUser(Auth::user()); + if ($entries->isEmpty()) { + return; + } + + $this->shouldPollChangelog = false; + $this->changelogFetchRequested = false; + $this->changelogPollAttempts = 0; + $this->dispatch('changelog-entries', entries: $entries->values()->all()); + + cache()->forget('user_unread_changelog_count_'.Auth::id()); + $this->dispatch('$refresh'); } public function closeWhatsNewModal() diff --git a/resources/views/livewire/settings-dropdown.blade.php b/resources/views/livewire/settings-dropdown.blade.php index efd359098..da96ab76e 100644 --- a/resources/views/livewire/settings-dropdown.blade.php +++ b/resources/views/livewire/settings-dropdown.blade.php @@ -8,6 +8,9 @@ this.mounted(); // Load all entries when component initializes this.allEntries = @js($entries->toArray()); + window.addEventListener('changelog-entries', (event) => { + this.allEntries = event.detail.entries ?? []; + }); }, markEntryAsRead(tagName) { // Update the entry in our local Alpine data @@ -103,7 +106,10 @@ return new Date(b.published_at) - new Date(a.published_at); }); } -}" @click.outside="dropdownOpen = false"> +}" @click.outside="dropdownOpen = false" wire:init="prefetchChangelog"> + @if ($shouldPollChangelog) + + @endif