Merge pull request #1767 from millmanorama/IG-hashsetmanager-performance

reduce db roundtrips in HashSetManager.getHashSetsForFileHelper
This commit is contained in:
Richard Cordovano 2015-12-11 14:08:54 -05:00
commit 26c7e2d597
2 changed files with 29 additions and 1 deletions

View File

@ -54,6 +54,8 @@ import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupManager;
import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupSortBy; import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupSortBy;
import static org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupSortBy.GROUP_BY_VALUE; import static org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupSortBy.GROUP_BY_VALUE;
import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.AbstractFile;
import org.sleuthkit.datamodel.BlackboardArtifact;
import org.sleuthkit.datamodel.BlackboardAttribute;
import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.Content;
import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.ContentTag;
import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.SleuthkitCase;
@ -475,6 +477,32 @@ public final class DrawableDB {
return con.isClosed(); return con.isClosed();
} }
/**
* get the names of the hashsets that the given fileID belongs to
*
* @param fileID the fileID to get all the Hashset names for
*
* @return a set of hash set names, each of which the given file belongs to
*
* @throws TskCoreException
*
*
* //TODO: this is mostly a cut and paste from *
* AbstractContent.getHashSetNames, is there away to dedupe?
*/
Set<String> getHashSetsForFile(long fileID) throws TskCoreException {
Set<String> hashNames = new HashSet<>();
ArrayList<BlackboardArtifact> artifacts = tskCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT, fileID);
for (BlackboardArtifact a : artifacts) {
List<BlackboardAttribute> attributes = a.getAttributes(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME);
for (BlackboardAttribute attr : attributes) {
hashNames.add(attr.getValueString());
}
}
return Collections.unmodifiableSet(hashNames);
}
/** /**
* get all the hash set names used in the db * get all the hash set names used in the db
* *

View File

@ -44,7 +44,7 @@ public class HashSetManager {
*/ */
private Set<String> getHashSetsForFileHelper(long fileID) { private Set<String> getHashSetsForFileHelper(long fileID) {
try { try {
return db.getFileFromID(fileID).getHashSetNames(); return db.getHashSetsForFile(fileID);
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
Logger.getLogger(HashSetManager.class.getName()).log(Level.SEVERE, "Failed to get Hash Sets for file", ex); Logger.getLogger(HashSetManager.class.getName()).log(Level.SEVERE, "Failed to get Hash Sets for file", ex);
return Collections.emptySet(); return Collections.emptySet();