<commit_before>from django.db.models.signals import post_save, post_delete
from django.db import models

from wagtail.wagtailsearch.index import Indexed
from wagtail.wagtailsearch.backends import get_search_backends


def post_save_signal_handler(instance, **kwargs):
    if instance not in type(instance).get_indexed_objects():
        return


    for backend in get_search_backends():
        backend.add(instance)


def post_delete_signal_handler(instance, **kwargs):
    if instance not in type(instance).get_indexed_objects():
        return

    for backend in get_search_backends():
        backend.delete(instance)


def register_signal_handlers():
    # Get list of models that should be indexed
    indexed_models = [model for model in models.get_models() if issubclass(model, Indexed)]<commit_msg>Improved performance of signal handlers<commit_after>from django.db.models.signals import post_save, post_delete
from django.db import models

from wagtail.wagtailsearch.index import Indexed
from wagtail.wagtailsearch.backends import get_search_backends


def post_save_signal_handler(instance, **kwargs):
    if not type(instance).get_indexed_objects().filter(id=instance.id).exists():
        return


    for backend in get_search_backends():
        backend.add(instance)


def post_delete_signal_handler(instance, **kwargs):
    if not type(instance).get_indexed_objects().filter(id=instance.id).exists():
        return

    for backend in get_search_backends():
        backend.delete(instance)


def register_signal_handlers():
    # Get list of models that should be indexed
    indexed_models = [model for model in models.get_models() if issubclass(model, Indexed)]
{'fraction_non_alphanumeric': 0.08194774346793349, 'fraction_numerical': 0.0, 'mean_word_length': 4.711864406779661, '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': '2388279', 'n_tokens_mistral': 496, 'n_tokens_neox': 479, 'n_words': 127}