diff --git a/changelog.html b/changelog.html
index 7943f6f41..90c29a2e1 100644
--- a/changelog.html
+++ b/changelog.html
@@ -48,6 +48,7 @@
- Requires Openfire 5.0.0
- Note: Chat rooms can, in certain circumstances, be destroyed, and then be recreated using the same name. For data recorded by previous versions of this plugin, the plugin will associate all room history with the latest 'reincarnation' of a room. Starting with this version, new data will be associated to the correct 'incarnation' of the room.
+ - [Issue #409] - Building Lucene index should not load all messages in memory
- [Issue #401] - Fixes: Update Jersey from 2.35 to 2.45
- [Issue #398] - Fixes: Missing translation for system property
- [Issue #392] - Fixes: Compatibility issue with Openfire 5.0.0
diff --git a/src/java/com/reucon/openfire/plugin/archive/impl/MucIndexer.java b/src/java/com/reucon/openfire/plugin/archive/impl/MucIndexer.java
index 75e9efb8c..5aea29a1a 100644
--- a/src/java/com/reucon/openfire/plugin/archive/impl/MucIndexer.java
+++ b/src/java/com/reucon/openfire/plugin/archive/impl/MucIndexer.java
@@ -134,16 +134,21 @@ private Instant indexMUCMessages( IndexWriter writer, Instant since )
// The entire process took under 8 seconds.
// Preventing the driver to collect all results at once depends on auto-commit from being disabled, at
// least for postgres. Getting a 'transaction' connection will ensure this (if supported).
+ // MSSQL differentiates between client-cursored and server-cursored result sets. For server-cursored result
+ // sets, the fetch buffer and scroll window are the same size (as opposed to fetch buffer containing all
+ // the rows). To hint that a server-cursored result set is desired, it should be configured to be 'forward
+ // only' as well as 'read only'.
con = DbConnectionManager.getTransactionConnection();
if ( since.equals( Instant.EPOCH ) ) {
- pstmt = con.prepareStatement(ALL_MUC_MESSAGES);
+ pstmt = con.prepareStatement(ALL_MUC_MESSAGES, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
} else {
- pstmt = con.prepareStatement(NEW_MUC_MESSAGES);
+ pstmt = con.prepareStatement(NEW_MUC_MESSAGES, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
pstmt.setString(1, StringUtils.dateToMillis(Date.from(since))); // This mimics org.jivesoftware.openfire.muc.spi.MUCPersistenceManager.saveConversationLogBatch
}
pstmt.setFetchSize(250);
+ pstmt.setFetchDirection(ResultSet.FETCH_FORWARD);
rs = pstmt.executeQuery();
long progress = 0;