Skip to content

Fix stale replyCount in /groups/-/topics due to Redis caching#1624

Closed
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-replycount-issue
Closed

Fix stale replyCount in /groups/-/topics due to Redis caching#1624
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-replycount-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

/groups/-/topics returns replyCount: 0 for most topics because it fetches topic data via fetchGroupTopicsByIDs(), which caches in Redis with a 24h TTL. Reply counts go stale immediately after caching.

The sibling endpoint /groups/:groupName/topics doesn't have this bug — it queries the DB directly.

  • Replace fetcher.fetchGroupTopicsByIDs(tids) with a direct DB query + convert.toGroupTopic(), consistent with how /groups/:groupName/topics already works
// Before: cached, stale replyCount
const topics = await fetcher.fetchGroupTopicsByIDs(tids);

// After: fresh from DB
const topicData = await db
  .select()
  .from(schema.chiiGroupTopics)
  .where(op.inArray(schema.chiiGroupTopics.id, tids));
const topics: Record<number, res.ITopic> = {};
for (const d of topicData) {
  topics[d.id] = convert.toGroupTopic(d);
}

Copilot AI added 2 commits April 6, 2026 23:38
…om Redis cache

The /groups/-/topics endpoint was using fetchGroupTopicsByIDs() which
caches topic data in Redis with a 24h TTL. This caused replyCount to
return stale values (often 0) because cached data didn't reflect new
replies. Replace the cached fetcher with a direct DB query, matching
the approach already used by /groups/:groupName/topics.

Agent-Logs-Url: https://github.com/bangumi/server-private/sessions/104d44e0-80de-476f-8c8a-0e9b751b76aa
Copilot AI changed the title [WIP] Fix replyCount field returning 0 in topics API Fix stale replyCount in /groups/-/topics due to Redis caching Apr 6, 2026
Copilot AI requested a review from trim21 April 6, 2026 23:39
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.05%. Comparing base (aa0eca1) to head (4a9bf85).
⚠️ Report is 17 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1624      +/-   ##
==========================================
- Coverage   57.29%   57.05%   -0.24%     
==========================================
  Files         151      151              
  Lines        6718     6721       +3     
  Branches     1392     1392              
==========================================
- Hits         3849     3835      -14     
- Misses       2203     2219      +16     
- Partials      666      667       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@trim21 trim21 closed this Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

小组最新话题 p1/groups/-/topics 的 replyCount 字段异常返回 0

2 participants