Skip to content

fix(communities): refresh active communities periodically#57

Merged
tomcasaburi merged 3 commits into
masterfrom
fix/community-auto-refresh
May 25, 2026
Merged

fix(communities): refresh active communities periodically#57
tomcasaburi merged 3 commits into
masterfrom
fix/community-auto-refresh

Conversation

@tomcasaburi
Copy link
Copy Markdown
Member

@tomcasaburi tomcasaburi commented May 25, 2026

Summary

  • Refresh active community instances immediately and every 15 minutes so long-lived tabs keep following community IPNS updates.
  • Clear community polling intervals during store reset and update pkc-js mocks/tests for repeated community updates.
  • Document the refresh cadence and regenerate LLM context files.

Verification

  • yarn build
  • yarn test
  • yarn test src/stores/communities/communities-store.test.ts
  • yarn test:coverage:hooks-stores (tests pass; command still exits nonzero because unrelated hooks/stores remain below the existing 100% gate, while communities-store is 100%)
  • yarn prettier
  • yarn llms:generate
  • git diff --check

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.

deleteCommunity and store reset tear down the matching interval, pending error timers, and listeners so deleted communities do not keep updating in the background. pkc-js mocks drop the single-call guard on update() and align updating / updatingstatechange with repeated updates.

README / llms-full.txt document the refresh cadence. Tests cover the timer behavior, cleanup on delete, lookup failures, string-address refresh, and a safer accounts-store re-import mock for localforage.

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

    • Communities now automatically refresh every 15 minutes after initial fetch, with long-lived tabs continuing to follow IPNS updates.
  • Documentation

    • Updated documentation explaining community refresh timing and behavior.
  • Tests

    • Added comprehensive test coverage for community refresh functionality and store initialization edge cases.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 25, 2026

📝 Walkthrough

Walkthrough

This PR implements background polling of communities every 15 minutes instead of a single update at initialization. Mocks now allow repeated update() calls and properly manage the updating flag. The store exports a configurable interval constant and uses setInterval to periodically refresh each community. Comprehensive tests validate polling behavior, error conditions, and the store's community management. Documentation explains the refresh cadence to end users.

Changes

Periodic Community Update Polling

Layer / File(s) Summary
Mock support for repeated Community updates
src/lib/pkc-js/pkc-js-mock.ts, src/lib/pkc-js/pkc-js-mock-content.ts
Removes the updateCalledTimes > 1 guard so Community.update() can be called repeatedly. Both mock files now explicitly set this.updating = false before marking the update as "succeeded" and emitting state-change events.
Communities store polling mechanism
src/stores/communities/communities-store.ts
Exports COMMUNITY_UPDATE_INTERVAL_MS = 15 * 60 * 1000 and replaces immediate community.update() calls with periodic polling via setInterval. Helper functions invoke community.update() with error tracing and manage interval cleanup during store reset.
Test coverage for polling behavior and store operations
src/stores/communities/communities-store.test.ts
Adds four new test cases: error handling when address is missing, refreshCommunity accepting string addresses, periodic update calls verified with fake timers, and createCommunity with a provided signer. Imports now include COMMUNITY_UPDATE_INTERVAL_MS and resetCommunitiesDatabaseAndStore.
Documentation of 15-minute refresh cadence
README.md, llms-full.txt, llms.txt
README and changelog entries updated to explain that communities are refreshed immediately and then every 15 minutes, allowing long-lived tabs to track IPNS updates.

Accounts store test infrastructure

Layer / File(s) Summary
Accounts store test module loading fix
src/stores/accounts/accounts-store.test.ts
Updates the "init edge cases" test to use query-qualified module imports (./accounts-store?init-skip) instead of vi.resetModules(), preserving localforage test driver setup while verifying early-return behavior when initialization has already occurred.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • bitsocialnet/bitsocial-react-hooks#49: Directly adjacent to this PR's periodic community polling implementation, as both modify how Communities are refreshed and updated in the store.

Poem

A rabbit hops through time,
Setting intervals with glee—
Communities refresh now,
Every fifteen minutes bright,
IPNS keeps pace, all night! 🐰⏰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(communities): refresh active communities periodically' clearly summarizes the main change: implementing periodic refresh of active communities, which is the core objective of the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/community-auto-refresh

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread src/stores/communities/communities-store.ts
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/stores/communities/communities-store.ts (1)

50-81: 💤 Low value

Clean 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's updating guard prevents overlaps.

📝 Optional: Add brief explanatory comment

Consider adding a short comment above startCommunityUpdatePolling documenting 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4539af0 and 40966f7.

📒 Files selected for processing (8)
  • README.md
  • llms-full.txt
  • llms.txt
  • src/lib/pkc-js/pkc-js-mock-content.ts
  • src/lib/pkc-js/pkc-js-mock.ts
  • src/stores/accounts/accounts-store.test.ts
  • src/stores/communities/communities-store.test.ts
  • src/stores/communities/communities-store.ts

Comment thread src/stores/accounts/accounts-store.test.ts Outdated
@tomcasaburi
Copy link
Copy Markdown
Member Author

Review follow-up:

  • Fixed Cursor Bugbot's deleted-community resurrection finding by keying community pollers and stopping the interval/listeners when deleteCommunity succeeds.
  • Added a regression that deletes a polled community, emits an old update, advances the 15-minute timer, and verifies the store/database stay deleted.
  • Addressed CodeRabbit's Vitest import concern by replacing the query-qualified import with vi.resetModules() plus a normal import("./accounts-store"), while preserving the configured localforage test driver through a scoped mock.

Verification:

  • yarn test src/stores/communities/communities-store.test.ts src/stores/accounts/accounts-store.test.ts
  • yarn test
  • yarn build
  • yarn test:coverage:hooks-stores ran all tests successfully, then the coverage verifier exited nonzero on unrelated baseline files; src/stores/communities/communities-store.ts is 100% in that report.

…refresh

# Conflicts:
#	src/stores/communities/communities-store.ts
@tomcasaburi tomcasaburi merged commit b6a3e98 into master May 25, 2026
8 checks passed
@tomcasaburi tomcasaburi deleted the fix/community-auto-refresh branch May 25, 2026 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant