Author: xor
Date: 2008-10-29 20:29:56 +0000 (Wed, 29 Oct 2008)
New Revision: 23195
Modified:
trunk/plugins/FMSPlugin/FMSMessage.java
Log:
Nice performance optimization. Please comment if you have a better idea.
Modified: trunk/plugins/FMSPlugin/FMSMessage.java
===================================================================
--- trunk/plugins/FMSPlugin/FMSMessage.java 2008-10-29 20:28:40 UTC (rev
23194)
+++ trunk/plugins/FMSPlugin/FMSMessage.java 2008-10-29 20:29:56 UTC (rev
23195)
@@ -29,8 +29,18 @@
private final FreenetURI mURI;
/**
- * The URI to which this message is a reply. Null if it is a thread.
+ * The URI of the thread this message belongs to.
+ * We do not need it to construct the thread-tree from messages, but it
boosts performance of thread-tree-construction:
+ * Thread-size (amount of replies) is usually infinitesimal compared to
the size of a FMSBoard (amount of threads).
+ * We receive messages in random order, therefore we will usually have
orphan messages of which we need to find the parents.
+ * If we receive the parent messages of those messages, we will be able
to find their orphan children faster if we only need to search in
+ * the thread they belong to and not in the whole FMSBoard - which may
contain many thousands of messages.
*/
+ private final FreenetURI mThreadURI;
+
+ /**
+ * The URI of the message to which this message is a reply. Null if it
is a thread.
+ */
private final FreenetURI mParentURI;
/**
@@ -59,7 +69,7 @@
*/
private UpdatableSortedLinkedList mChildren = new
UpdatableSortedLinkedList();
- public FMSMessage(FreenetURI newURI, FreenetURI newParentURI,
Set<FMSBoard> newBoards, FMSIdentity newAuthor, String newTitle, Date newDate,
String newText, List<FreenetURI> newAttachments) {
+ public FMSMessage(FreenetURI newURI, FreenetURI newThreadURI,
FreenetURI newParentURI, Set<FMSBoard> newBoards, FMSIdentity newAuthor, String
newTitle, Date newDate, String newText, List<FreenetURI> newAttachments) {
if (newURI == null || newBoards == null || newAuthor == null)
throw new IllegalArgumentException();
@@ -73,6 +83,7 @@
throw new IllegalArgumentException("Invalid message
text in message " + newURI);
mURI = newURI;
+ mThreadURI = newThreadURI;
mParentURI = newParentURI;
mBoards = new ArrayList<FMSBoard>(newBoards);
Collections.sort(mBoards);
@@ -90,6 +101,10 @@
return mURI;
}
+ public FreenetURI getThreadURI() {
+ return mThreadURI;
+ }
+
public FreenetURI getParentURI() {
return mParentURI;
}