fix(communities): refresh active communities periodically#57
Conversation
📝 WalkthroughWalkthroughThis PR implements background polling of communities every 15 minutes instead of a single update at initialization. Mocks now allow repeated ChangesPeriodic Community Update Polling
Accounts store test infrastructure
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 40966f7. Configure here.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/stores/communities/communities-store.ts (1)
50-81: 💤 Low valueClean polling implementation with proper error handling.
The immediate update followed by interval-based polling correctly implements the "refresh immediately and then every 15 minutes" requirement. Non-blocking
community.update()calls are appropriate for background tasks, and the mock'supdatingguard prevents overlaps.📝 Optional: Add brief explanatory comment
Consider adding a short comment above
startCommunityUpdatePollingdocumenting the 15-minute cadence and why errors are logged at trace level:+// Polls each loaded Community every 15 minutes to track IPNS updates. +// Errors are logged at trace level since background updates are non-critical. const startCommunityUpdatePolling = (🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/stores/communities/communities-store.ts` around lines 50 - 81, Add a short explanatory comment above startCommunityUpdatePolling describing that it performs an immediate non-blocking refresh via updateCommunity and then schedules subsequent refreshes every 15 minutes using COMMUNITY_UPDATE_INTERVAL_MS, and note that errors from community.update are logged at trace level via log.trace (so failures are non-fatal/background). Reference the startCommunityUpdatePolling and updateCommunity functions and the COMMUNITY_UPDATE_INTERVAL_MS constant when adding the comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/stores/accounts/accounts-store.test.ts`:
- Line 129: The test currently bypasses Vitest module caching by dynamically
importing "./accounts-store?init-skip" which is unreliable; instead call
vi.resetModules() in a beforeEach and then perform a normal dynamic import of
"./accounts-store" so each test gets a fresh module instance — replace usages of
import("./accounts-store?init-skip") with import("./accounts-store") and ensure
vi.resetModules() is invoked in the test suite's beforeEach to guarantee
isolation for the accounts-store initialization.
---
Nitpick comments:
In `@src/stores/communities/communities-store.ts`:
- Around line 50-81: Add a short explanatory comment above
startCommunityUpdatePolling describing that it performs an immediate
non-blocking refresh via updateCommunity and then schedules subsequent refreshes
every 15 minutes using COMMUNITY_UPDATE_INTERVAL_MS, and note that errors from
community.update are logged at trace level via log.trace (so failures are
non-fatal/background). Reference the startCommunityUpdatePolling and
updateCommunity functions and the COMMUNITY_UPDATE_INTERVAL_MS constant when
adding the comment.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: cd438af8-2a4a-44b9-9e8e-b895a145f01a
📒 Files selected for processing (8)
README.mdllms-full.txtllms.txtsrc/lib/pkc-js/pkc-js-mock-content.tssrc/lib/pkc-js/pkc-js-mock.tssrc/stores/accounts/accounts-store.test.tssrc/stores/communities/communities-store.test.tssrc/stores/communities/communities-store.ts
|
Review follow-up:
Verification:
|
…refresh # Conflicts: # src/stores/communities/communities-store.ts

Summary
Verification
Note
Medium Risk
Changes how long-lived clients keep community snapshots fresh (background timers and listener lifecycle); behavior is well tested but affects core feed/community staleness in open tabs.
Overview
Active communities loaded into the store now call
community.update()immediately and again every 15 minutes via new polling helpers, so long-lived tabs can follow IPNS changes instead of stopping after the first refresh.deleteCommunityand store reset tear down the matching interval, pending error timers, and listeners so deleted communities do not keep updating in the background.pkc-jsmocks drop the single-call guard onupdate()and alignupdating/updatingstatechangewith repeated updates.README /
llms-full.txtdocument the refresh cadence. Tests cover the timer behavior, cleanup on delete, lookup failures, string-address refresh, and a safer accounts-store re-import mock forlocalforage.Reviewed by Cursor Bugbot for commit 44dc13f. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
Release Notes
New Features
Documentation
Tests