<commit_before>package org.commcare.modern.engine.cases;

import org.commcare.cases.model.Case;
import org.commcare.cases.query.QueryCache;

import java.util.HashMap;
import java.util.LinkedHashSet;

/**
 * A case group result cache keeps track of different sets of "Bulk" cases 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 cases themselves. Rather a CaseObjectCache should
 * be used to track the resulting cases. This will ensure that cache can be attached to the
 * appropriate lifecycle
 *
 * Created by ctsims on 1/25/2017.
 */

public class CaseGroupResultCache implements QueryCache {

    private HashMap<String,LinkedHashSet<Integer>> bulkFetchBodies = new HashMap<>();

    public void reportBulkCaseBody(String key, LinkedHashSet<Integer> ids) {
        if(bulkFetchBodies.containsKey(key)) {
            return;
        }
        bulkFetchBodies.put(key, ids);
    }

    public boolean hasMatchingCaseSet(int recordId) {
        return getTranche(recordId) != null;
    }

    public LinkedHashSet<Integer> getTranche(int recordId) {
        for(LinkedHashSet<Integer> tranche: bulkFetchBodies.values()) {
            if(tranche.contains(recordId)){
                return tranche;
            }
        }
        return null;
    }
}<commit_msg>Clarify tranche keys for debugging outputs<commit_after>package org.commcare.modern.engine.cases;

import org.commcare.cases.model.Case;
import org.commcare.cases.query.QueryCache;
import org.commcare.modern.util.Pair;

import java.util.HashMap;
import java.util.LinkedHashSet;

/**
 * A case group result cache keeps track of different sets of "Bulk" cases 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 cases themselves. Rather a CaseObjectCache should
 * be used to track the resulting cases. This will ensure that cache can be attached to the
 * appropriate lifecycle
 *
 * Created by ctsims on 1/25/2017.
 */

public class CaseGroupResultCache implements QueryCache {

    private HashMap<String,LinkedHashSet<Integer>> bulkFetchBodies = new HashMap<>();

    public void reportBulkCaseBody(String key, LinkedHashSet<Integer> ids) {
        if(bulkFetchBodies.containsKey(key)) {
            return;
        }
        bulkFetchBodies.put(key, ids);
    }

    public boolean hasMatchingCaseSet(int recordId) {
        return getTranche(recordId) != null;
    }

    public Pair<String, LinkedHashSet<Integer>> getTranche(int recordId) {
        for(String key : bulkFetchBodies.keySet()) {
            LinkedHashSet<Integer> tranche = bulkFetchBodies.get(key);
            if(tranche.contains(recordId)){
                return new Pair<>(key, tranche);
            }
        }
        return null;
    }
}
{'fraction_non_alphanumeric': 0.08085912823752368, 'fraction_numerical': 0.004421983575489577, 'mean_word_length': 3.3682758620689657, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3524712', 'n_tokens_mistral': 889, 'n_tokens_neox': 849, 'n_words': 285}