Commit 58df7bd4 authored by Christian Schudt's avatar Christian Schudt
parents bb1f122e 21e16875
...@@ -31,6 +31,7 @@ import org.jivesoftware.database.DbConnectionManager; ...@@ -31,6 +31,7 @@ import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.openfire.PacketRouter; import org.jivesoftware.openfire.PacketRouter;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.muc.*; import org.jivesoftware.openfire.muc.*;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.StringUtils; import org.jivesoftware.util.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -50,6 +51,9 @@ import org.xmpp.packet.JID; ...@@ -50,6 +51,9 @@ import org.xmpp.packet.JID;
public class MUCPersistenceManager { public class MUCPersistenceManager {
private static final Logger Log = LoggerFactory.getLogger(MUCPersistenceManager.class); private static final Logger Log = LoggerFactory.getLogger(MUCPersistenceManager.class);
// property name for optional number of days to limit persistent MUC history during reload (OF-764)
private static final String MUC_HISTORY_RELOAD_LIMIT = "xmpp.muc.history.reload.limit";
private static final String GET_RESERVED_NAME = private static final String GET_RESERVED_NAME =
"SELECT nickname FROM ofMucMember WHERE roomID=? AND jid=?"; "SELECT nickname FROM ofMucMember WHERE roomID=? AND jid=?";
...@@ -219,21 +223,28 @@ public class MUCPersistenceManager { ...@@ -219,21 +223,28 @@ public class MUCPersistenceManager {
room.setPersistent(true); room.setPersistent(true);
DbConnectionManager.fastcloseStmt(rs, pstmt); DbConnectionManager.fastcloseStmt(rs, pstmt);
pstmt = con.prepareStatement(LOAD_HISTORY); // Recreate the history only for the rooms that have the conversation logging
// Recreate the history until two days ago // enabled
long from = System.currentTimeMillis() - (86400000 * 2); if (room.isLogEnabled()) {
pstmt.setString(1, StringUtils.dateToMillis(new Date(from))); pstmt = con.prepareStatement(LOAD_HISTORY);
pstmt.setLong(2, room.getID()); // Reload the history, using "muc.history.reload.limit" (days) if present
rs = pstmt.executeQuery(); long from = 0;
while (rs.next()) { String reloadLimit = JiveGlobals.getProperty(MUC_HISTORY_RELOAD_LIMIT);
String senderJID = rs.getString(1); if (reloadLimit != null) {
String nickname = rs.getString(2); // if the property is defined, but not numeric, default to 2 (days)
Date sentDate = new Date(Long.parseLong(rs.getString(3).trim())); int reloadLimitDays = JiveGlobals.getIntProperty(MUC_HISTORY_RELOAD_LIMIT, 2);
String subject = rs.getString(4); Log.warn("MUC history reload limit set to " + reloadLimitDays + " days");
String body = rs.getString(5); from = System.currentTimeMillis() - (86400000 * reloadLimitDays);
// Recreate the history only for the rooms that have the conversation logging }
// enabled pstmt.setString(1, StringUtils.dateToMillis(new Date(from)));
if (room.isLogEnabled()) { pstmt.setLong(2, room.getID());
rs = pstmt.executeQuery();
while (rs.next()) {
String senderJID = rs.getString(1);
String nickname = rs.getString(2);
Date sentDate = new Date(Long.parseLong(rs.getString(3).trim()));
String subject = rs.getString(4);
String body = rs.getString(5);
room.getRoomHistory().addOldMessage(senderJID, nickname, sentDate, subject, room.getRoomHistory().addOldMessage(senderJID, nickname, sentDate, subject,
body); body);
} }
...@@ -534,7 +545,15 @@ public class MUCPersistenceManager { ...@@ -534,7 +545,15 @@ public class MUCPersistenceManager {
connection = DbConnectionManager.getConnection(); connection = DbConnectionManager.getConnection();
statement = connection.prepareStatement(LOAD_ALL_HISTORY); statement = connection.prepareStatement(LOAD_ALL_HISTORY);
final long from = System.currentTimeMillis() - (86400000 * 2); // Recreate the history until two days ago // Reload the history, using "muc.history.reload.limit" (days) if present
long from = 0;
String reloadLimit = JiveGlobals.getProperty(MUC_HISTORY_RELOAD_LIMIT);
if (reloadLimit != null) {
// if the property is defined, but not numeric, default to 2 (days)
int reloadLimitDays = JiveGlobals.getIntProperty(MUC_HISTORY_RELOAD_LIMIT, 2);
Log.warn("MUC history reload limit set to " + reloadLimitDays + " days");
from = System.currentTimeMillis() - (86400000 * reloadLimitDays);
}
statement.setLong(1, serviceID); statement.setLong(1, serviceID);
statement.setString(2, StringUtils.dateToMillis(new Date(from))); statement.setString(2, StringUtils.dateToMillis(new Date(from)));
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
...@@ -542,8 +561,8 @@ public class MUCPersistenceManager { ...@@ -542,8 +561,8 @@ public class MUCPersistenceManager {
while (resultSet.next()) { while (resultSet.next()) {
try { try {
LocalMUCRoom room = rooms.get(resultSet.getLong(1)); LocalMUCRoom room = rooms.get(resultSet.getLong(1));
// Skip to the next position if the room does not exist // Skip to the next position if the room does not exist or if history is disabled
if (room == null) { if (room == null || !room.isLogEnabled()) {
continue; continue;
} }
String senderJID = resultSet.getString(2); String senderJID = resultSet.getString(2);
...@@ -551,10 +570,7 @@ public class MUCPersistenceManager { ...@@ -551,10 +570,7 @@ public class MUCPersistenceManager {
Date sentDate = new Date(Long.parseLong(resultSet.getString(4).trim())); Date sentDate = new Date(Long.parseLong(resultSet.getString(4).trim()));
String subject = resultSet.getString(5); String subject = resultSet.getString(5);
String body = resultSet.getString(6); String body = resultSet.getString(6);
// Recreate the history only for the rooms that have the conversation logging enabled. room.getRoomHistory().addOldMessage(senderJID, nickname, sentDate, subject, body);
if (room.isLogEnabled()) {
room.getRoomHistory().addOldMessage(senderJID, nickname, sentDate, subject, body);
}
} catch (SQLException e) { } catch (SQLException e) {
Log.warn("A database exception prevented the history for one particular MUC room to be loaded from the database.", e); Log.warn("A database exception prevented the history for one particular MUC room to be loaded from the database.", e);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment