Skip to content

Commit

Permalink
sepinf-inc#2286: cache message participants in UFEDChatParser
Browse files Browse the repository at this point in the history
  • Loading branch information
aberenguel committed Oct 18, 2024
1 parent 2d43244 commit 0a81f7d
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -78,6 +79,8 @@ public class UFEDChatParser extends AbstractParser {
private boolean ignoreEmptyChats = false;
private int minChatSplitSize = 6000000;

private Map<String, IItemReader> participantsCache = new HashMap<>();

private static Set<MediaType> supportedTypes = MediaType.set(UFED_CHAT_MIME, UFED_CHAT_WA_MIME,
UFED_CHAT_TELEGRAM_MIME);

Expand Down Expand Up @@ -238,6 +241,7 @@ public void parse(InputStream inputStream, ContentHandler handler, Metadata chat

} finally {
xhtml.endDocument();
participantsCache.clear();
}
}

Expand Down Expand Up @@ -377,6 +381,10 @@ private IItemReader lookupParticipant(IItemSearcher searcher, Metadata chatMetad
return null;
}

if (participantsCache.containsKey(userID)) {
return participantsCache.get(userID);
}

String account = readUfedMetadata(chatMetadata, "Account");
String source = readUfedMetadata(chatMetadata, "Source");
String query = BasicProps.CONTENTTYPE + ":\"" + MediaTypes.UFED_CONTACT_MIME.toString() + "\"" //
Expand All @@ -386,14 +394,16 @@ private IItemReader lookupParticipant(IItemSearcher searcher, Metadata chatMetad
+ " && " + searcher.escapeQuery(ExtraProperties.UFED_META_PREFIX + "UserID") + ":\"" + userID + "\"";

List<IItemReader> results = searcher.search(query);
IItemReader result = null;
if (!results.isEmpty()) {
if (results.size() > 1) {
logger.warn("Found more than one participant for [{}]: {}", account, results);
}
return results.get(0);
result = results.get(0);
}

return null;
participantsCache.put(userID, result);
return result;
}

private void fillParticipantInfo(IItemSearcher searcher, Metadata chatMetadata, Metadata targetMetadata,
Expand Down

0 comments on commit 0a81f7d

Please sign in to comment.