Skip to content

OF-3364: Limit MUC history reload query at the database level - #3487

Merged
guusdk merged 1 commit into
igniterealtime:mainfrom
guusdk:OF-3364_MUC-history-parent-debug
Sep 8, 2026
Merged

OF-3364: Limit MUC history reload query at the database level#3487
guusdk merged 1 commit into
igniterealtime:mainfrom
guusdk:OF-3364_MUC-history-parent-debug

Conversation

@guusdk

@guusdk guusdk commented Sep 8, 2026

Copy link
Copy Markdown
Member

MUCPersistenceManager#loadHistory previously fetched all rows since the configured reload window and then scrolled/trimmed the ResultSet client-side to keep only the last maxNumber messages.

This relied on scrollable, TYPE_SCROLL_INSENSITIVE result sets, which are not reliably supported across all database backends (e.g. disabled outright for CockroachDB), and could transfer far more data than was ultimately retained for rooms with long histories.

Instead, build the query dynamically using DbConnectionManager's result-set-limit facilities (LIMIT / TOP / FETCH FIRST ... ROWS ONLY, per database type) so the limit is pushed down to the database.

Also adds debug logging around the reload window and returned row count to make future over-fetching easier to spot.

MUCPersistenceManager#loadHistory previously fetched all rows since the configured reload window and then scrolled/trimmed the ResultSet client-side to keep only the last maxNumber messages.

This relied on scrollable, TYPE_SCROLL_INSENSITIVE result sets, which are not reliably supported across all database backends (e.g. disabled outright for CockroachDB), and could transfer far more data than was ultimately retained for rooms with long histories.

Instead, build the query dynamically using DbConnectionManager's result-set-limit facilities (LIMIT / TOP / FETCH FIRST ... ROWS ONLY, per database type) so the limit is pushed down to the database.

Also adds debug logging around the reload window and returned row count to make future over-fetching easier to spot.
@guusdk
guusdk requested a review from Fishbowler September 8, 2026 07:50
@guusdk guusdk added the backport 5.1 on merge, GHA will generate a PR with these changes against 5.1 branch label Sep 8, 2026
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 39fd1139-5d01-46e8-96fa-08b82502068c

📥 Commits

Reviewing files that changed from the base of the PR and between 8252a81 and e432534.

📒 Files selected for processing (1)
  • xmppserver/src/main/java/org/jivesoftware/openfire/muc/spi/MUCPersistenceManager.java

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

loadHistory now uses dynamically built SQL instead of a fixed query and scrollable result sets. The query applies database-specific TOP, LIMIT, or FETCH FIRST syntax when a maximum message count is set. Parameter binding adapts to the selected syntax. Limited results are fetched in descending time order, then reversed before insertion so room history remains chronological. Debug logging reports loaded message counts and applied limits.

Merge Risk: ⚪ Minimal · up to e4325

MUC history loading now limits database results directly while retaining chronological message order, reducing unnecessary data transfer without an identified merge-blocking behavior risk.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description directly explains the changes to MUCPersistenceManager#loadHistory, including database-level result limits, removal of scrollable result-set reliance, reduced data transfe…
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.

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.

@guusdk
guusdk requested a lite review from Copilot September 8, 2026 07:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@guusdk
guusdk merged commit 69b8f1d into igniterealtime:main Sep 8, 2026
81 of 83 checks passed
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Successfully created backport PR for 5.1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 5.1 on merge, GHA will generate a PR with these changes against 5.1 branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants