-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #607 from dimagi/ctsims/fixture_performance_improv…
…ement Performance: Allow bulk lookups with indexed fixtures
- Loading branch information
Showing
20 changed files
with
784 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import org.commcare.cases.model.StorageIndexedTreeElementModel; | ||
import org.commcare.cases.query.QueryContext; | ||
import org.commcare.cases.query.QuerySensitive; | ||
import org.javarosa.core.model.instance.TreeElement; | ||
import org.javarosa.core.model.instance.TreeReference; | ||
|
||
|
@@ -12,7 +13,7 @@ | |
* | ||
* @author Phillip Mates ([email protected]) | ||
*/ | ||
public class IndexedFixtureChildElement extends StorageBackedChildElement<StorageIndexedTreeElementModel> { | ||
public class IndexedFixtureChildElement extends StorageBackedChildElement<StorageIndexedTreeElementModel> implements QuerySensitive{ | ||
private TreeElement empty; | ||
|
||
protected IndexedFixtureChildElement(StorageInstanceTreeElement<StorageIndexedTreeElementModel, ?> parent, | ||
|
@@ -65,4 +66,9 @@ public static IndexedFixtureChildElement buildFixtureChildTemplate(IndexedFixtur | |
template.empty.setMult(TreeReference.INDEX_TEMPLATE); | ||
return template; | ||
} | ||
|
||
@Override | ||
public void prepareForUseInCurrentContext(QueryContext queryContext) { | ||
cache(queryContext); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
src/main/java/org/commcare/modern/engine/cases/CaseObjectCache.java
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
src/main/java/org/commcare/modern/engine/cases/CaseSetResultCache.java
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
src/main/java/org/commcare/modern/engine/cases/RecordObjectCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.commcare.modern.engine.cases; | ||
|
||
import org.commcare.cases.model.Case; | ||
import org.commcare.cases.query.QueryCache; | ||
|
||
import java.util.HashMap; | ||
|
||
/** | ||
* A straightforward cache object query cache. Stores objects by their record ID. | ||
* | ||
* Used by other optimizations to isolate doing bulk loads and ensure that they are relevant | ||
* when they occur | ||
* | ||
* Created by ctsims on 6/22/2017. | ||
*/ | ||
|
||
public class RecordObjectCache<T> implements QueryCache { | ||
|
||
private HashMap<Integer, T> cachedRecordObjects = new HashMap<>(); | ||
|
||
public boolean isLoaded(int recordId) { | ||
return cachedRecordObjects.containsKey(recordId); | ||
} | ||
|
||
public HashMap<Integer, T> getLoadedCaseMap() { | ||
return cachedRecordObjects; | ||
} | ||
|
||
public T getLoadedRecordObject(int recordId) { | ||
return cachedRecordObjects.get(recordId); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/org/commcare/modern/engine/cases/RecordSetResultCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.commcare.modern.engine.cases; | ||
|
||
import org.commcare.cases.query.QueryCache; | ||
import org.commcare.modern.util.Pair; | ||
|
||
import java.util.HashMap; | ||
import java.util.LinkedHashSet; | ||
|
||
/** | ||
* A record set result cache keeps track of different sets of "Bulk" record which are | ||
* likely to have data or operations tracked about them (IE: results of a common query which | ||
* are likely to have further filtering applied.) | ||
* | ||
* Since these results are often captured/reported before a context is escalated, this cache | ||
* doesn't directly hold the resulting cached records themselves. Rather a RecordObjectCache should | ||
* be used to track the resulting records. This will ensure that cache can be attached to the | ||
* appropriate lifecycle | ||
* | ||
* Created by ctsims on 1/25/2017. | ||
*/ | ||
|
||
public class RecordSetResultCache implements QueryCache { | ||
|
||
private HashMap<String,Pair<String, LinkedHashSet<Integer>>> bulkFetchBodies = new HashMap<>(); | ||
|
||
/** | ||
* Report a set of bulk records that are likely to be needed as a group. | ||
* | ||
* @param key A unique key for the provided record set. It is presumed that if the key is | ||
* already in use that the id set is redundant. | ||
* @param storageSetID The name of the Storage where the records are stored. | ||
* @param ids The record set ID's | ||
*/ | ||
public void reportBulkRecordSet(String key, String storageSetID, LinkedHashSet<Integer> ids) { | ||
String fullKey = key +"|" + storageSetID; | ||
if (bulkFetchBodies.containsKey(fullKey)) { | ||
return; | ||
} | ||
bulkFetchBodies.put(fullKey, new Pair<>(storageSetID, ids)); | ||
} | ||
|
||
public boolean hasMatchingRecordSet(String recordSetName, int recordId) { | ||
return getRecordSetForRecordId(recordSetName, recordId) != null; | ||
} | ||
|
||
public Pair<String, LinkedHashSet<Integer>> getRecordSetForRecordId(String recordSetName, | ||
int recordId) { | ||
for (String key : bulkFetchBodies.keySet()) { | ||
Pair<String, LinkedHashSet<Integer>> tranche = bulkFetchBodies.get(key); | ||
if (tranche.second.contains(recordId) && tranche.first.equals(recordSetName)) { | ||
return new Pair<>(key, tranche.second); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.