<commit_before>from dplace_app.models import Source

def get_source(source='EA'):
    if source == 'EA':
        try:
            return Source.objects.get(year="1999", author="<NAME>.")
        except Source.DoesNotExist:
            return Source.objects.create(
                year="1999",
                author="<NAME>.",
                reference="<NAME>., <NAME>, <NAME>, III, <NAME>, <NAME>, and W. T. Divale. 1999. Ethnographic Atlas. World Cultures 10:24-136 (codebook)",
                focal_year='',
                subcase='',
            )
    elif source == 'Binford':
        try:
            return Source.objects.get(year="2001", author="Binford")
        except Source.DoesNotExist:
            return Source.objects.create(
                year="2001",
                author="Binford",
                reference="Binford, L. 2001. Constructing Frames of Reference: An Analytical Method for Archaeological Theory Building Using Hunter-gatherer and Environmental Data Sets. University of California Press",
                focal_year='',
                subcase='',
            )
    else:
        raise ValueError("Unknown Source: %s" % source)<commit_msg>adding some rudimentary caching to go nice on the database<commit_after>from dplace_app.models import Source

_SOURCE_CACHE = {}
def get_source(source='EA'):
    if source in _SOURCE_CACHE:
        return _SOURCE_CACHE[source]
    
    if source == 'EA':
        try:
            o = Source.objects.get(year="1999", author="<NAME>.")
        except Source.DoesNotExist:
            o = Source.objects.create(
                year="1999",
                author="<NAME>.",
                reference="<NAME>., <NAME>, <NAME>, III, <NAME>, <NAME>, and <NAME>. Divale. 1999. Ethnographic Atlas. World Cultures 10:24-136 (codebook)",
                focal_year='',
                subcase='',
            )
    elif source == 'Binford':
        try:
            o = Source.objects.get(year="2001", author="Binford")
        except Source.DoesNotExist:
            o = Source.objects.create(
                year="2001",
                author="Binford",
                reference="Binford, L. 2001. Constructing Frames of Reference: An Analytical Method for Archaeological Theory Building Using Hunter-gatherer and Environmental Data Sets. University of California Press",
                focal_year='',
                subcase='',
            )
    else:
        raise ValueError("Unknown Source: %s" % source)
    _SOURCE_CACHE[source] = o
    return o
{'fraction_non_alphanumeric': 0.11792639493470518, 'fraction_numerical': 0.02453502176493866, 'mean_word_length': 1.9988137603795966, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, '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': '1329852', 'n_tokens_mistral': 735, 'n_tokens_neox': 667, 'n_words': 184}