<commit_before>from celery.decorators import task
from django.db.models import get_model
import re


recalc_needed_re = re.compile("(.*)_recalculation_needed$")
@task
def offload_cache_recalculation(app, model, obj_id, **kwargs):
    logger = offload_cache_recalculation.get_logger(**kwargs)
    model = get_model(app,model)
    try:
        obj = model.objects.get(pk=obj_id)
        for f in model._meta.fields:
            match = recalc_needed_re.search(f.name)
            if match:
                basename = match.groups()[0]
                getattr(obj, "recalculate_%s" % basename)()
    except model.DoesNotExist:
        logger.info('%s.%s with pk %s does not exist.  Was offload_cache_recalculation called before initial object creation or after object deletion?' % (app, model, obj_id))
<commit_msg>Fixed bug where cache recalc wasn't checking whether recalc was needed<commit_after>from celery.decorators import task
from django.db.models import get_model
import re


recalc_needed_re = re.compile("(.*)_recalculation_needed$")
@task
def offload_cache_recalculation(app, model, obj_id, **kwargs):
    logger = offload_cache_recalculation.get_logger(**kwargs)
    model = get_model(app,model)
    try:
        obj = model.objects.get(pk=obj_id)
        for f in model._meta.fields:
            match = recalc_needed_re.search(f.name)
            if match and getattr(obj, f.name):
                basename = match.groups()[0]
                getattr(obj, "recalculate_%s" % basename)()
    except model.DoesNotExist:
        logger.info('%s.%s with pk %s does not exist.  Was offload_cache_recalculation called before initial object creation or after object deletion?' % (app, model, obj_id))

{'fraction_non_alphanumeric': 0.1025791324736225, 'fraction_numerical': 0.0011723329425556857, 'mean_word_length': 3.433766233766234, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5974191', 'n_tokens_mistral': 562, 'n_tokens_neox': 526, 'n_words': 135}