Repository navigation
Keep bot page totals on rooms.messages_count - #321
Open
thomasklemm wants to merge 4 commits into
Open
thomasklemm wants to merge 4 commits into
thomasklemm wants to merge 4 commits into
Conversation
X-Total-Count on GET /rooms/:id/:bot_key/messages was COUNT(*) of the room on every page. Serve the header from a counter cache instead. Fixes basecamp#309. Co-authored-by: Thomas Klemm <github@tklemm.eu>
The pagination test already checks X-Total-Count. The regex wrap and second GET are extra. Co-authored-by: Thomas Klemm <github@tklemm.eu>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approved
The migration, model behavior, API usage, and regression coverage consistently implement the cached total.
Review effort: Balanced
Findings: None
What changed in this PR
Caches room message totals to avoid repeated COUNT(*) queries in the bot messages API.
Changes:
- Adds and backfills
rooms.messages_count. - Maintains the count through Rails counter caching.
- Uses and tests the cached count for pagination headers.
[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or rungh pr ready --undo.
Click "Ready for review" or rungh pr readyto reengage.
| File | Description |
|---|---|
app/controllers/messages/by_bots_controller.rb |
Reads the cached total for the response header. |
app/models/message.rb |
Enables the room counter cache. |
db/migrate/20261005123000_add_messages_count_to_rooms.rb |
Adds and backfills the counter column. |
db/schema.rb |
Records the new column and schema version. |
test/controllers/messages/by_bots_controller_test.rb |
Initializes accurate fixture counters for API tests. |
test/models/message_test.rb |
Tests increments and decrements. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Keep rooms.messages_count and the room_id/created_at messages index. Co-authored-by: Thomas Klemm <github@tklemm.eu>
thomasklemm
added a commit
to roundhouse-rb/once-campfire
that referenced
this pull request
Oct 5, 2026
From thomasklemm:cursor/bot-messages-total-without-count-8545 (upstream PR state at merge: OPEN).
thomasklemm
added a commit
to roundhouse-rb/once-campfire
that referenced
this pull request
Oct 5, 2026
From thomasklemm:cursor/bot-messages-total-without-count-8545 (upstream PR state at merge: OPEN).
thomasklemm
added a commit
to roundhouse-rb/once-campfire
that referenced
this pull request
Oct 5, 2026
From thomasklemm:cursor/bot-messages-total-without-count-8545 (upstream PR state at merge: OPEN).
…-total-without-count-8545 Co-authored-by: Thomas Klemm <github@tklemm.eu>
thomasklemm
added a commit
to roundhouse-rb/once-campfire
that referenced
this pull request
Oct 5, 2026
…-prs-8545 Stack basecamp basecamp#318–basecamp#321 onto preview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bot
indexsetX-Total-Countwith@room.messages.count, aCOUNT(*)on every page.The header now reads
rooms.messages_count. Creating and destroying messages keeps the counter in step.Fixes #309