Load chat history from the end of the log only
Chat logs grow forever, and every connect and every private chat opened read the whole log to keep its last 1000 entries. History now reads the last 4 MiB, which holds far more than that; searching still reads the whole log. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -80,4 +80,20 @@ class ChatLogStoreTest {
|
||||
assertTrue(history.get(0).contains("first line<br><br>third line"), history.get(0));
|
||||
assertTrue(history.get(1).contains("reply"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void historyComesFromTheEndOfALongLog() throws Exception {
|
||||
ChatLogStore logs = new ChatLogStore(temp, "+Tyg2JtxE8vRNZp+JiUBnmBh0MY=");
|
||||
logs.appendMessage(ChatLogScope.CHANNEL, false, 5, "uid", "alice", "start");
|
||||
Path txt = logs.serverDir().resolve("channel.txt");
|
||||
StringBuilder filler = new StringBuilder();
|
||||
for (int i = 0; i < 200_000; i++) filler.append("<12:00:00> alice: žluťoučký kůň ").append(i).append('\n');
|
||||
Files.writeString(txt, filler, java.nio.file.StandardOpenOption.APPEND);
|
||||
logs.appendMessage(ChatLogScope.CHANNEL, false, 5, "uid", "bob", "the latest");
|
||||
|
||||
List<String> history = logs.channelHtmlHistory();
|
||||
assertEquals(ChatLogStore.HISTORY_LIMIT, history.size());
|
||||
assertTrue(history.get(history.size() - 1).contains("the latest"));
|
||||
assertTrue(history.get(0).contains("žluťoučký kůň"), history.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user