From 0a81f7d95e6398279901fcc01fc51e28742a0554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Berenguel?= Date: Fri, 18 Oct 2024 10:13:39 -0300 Subject: [PATCH] #2286: cache message participants in UFEDChatParser --- .../java/iped/parsers/ufed/UFEDChatParser.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/ufed/UFEDChatParser.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/ufed/UFEDChatParser.java index 157a99b22e..58cd1ebd4f 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/ufed/UFEDChatParser.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/ufed/UFEDChatParser.java @@ -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; @@ -78,6 +79,8 @@ public class UFEDChatParser extends AbstractParser { private boolean ignoreEmptyChats = false; private int minChatSplitSize = 6000000; + private Map participantsCache = new HashMap<>(); + private static Set supportedTypes = MediaType.set(UFED_CHAT_MIME, UFED_CHAT_WA_MIME, UFED_CHAT_TELEGRAM_MIME); @@ -238,6 +241,7 @@ public void parse(InputStream inputStream, ContentHandler handler, Metadata chat } finally { xhtml.endDocument(); + participantsCache.clear(); } } @@ -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() + "\"" // @@ -386,14 +394,16 @@ private IItemReader lookupParticipant(IItemSearcher searcher, Metadata chatMetad + " && " + searcher.escapeQuery(ExtraProperties.UFED_META_PREFIX + "UserID") + ":\"" + userID + "\""; List 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,