<commit_before>
_database_to_use = {
    ('search', 'search'): 'transient'
}


class DatabaseRouter(object):
    """
    A Database router.
    Some models do not need (and must not be backuped).
    So we route them to the transient base.
    """
    def db_for_read(self, model, **hints):
        """
        Return the database from which this model can be read,
        or None to use the default database.
        """
        app_model = model._meta.app_label, model._meta.model_name
        return _database_to_use.get(app_model)

    def db_for_write(self, model, **hints):
        """
        Return database for which this model can be write,
        or None to use the default database.
        """
        app_model = model._meta.app_label, model._meta.model_name
        return _database_to_use.get(app_model)

    def allow_relation(self, obj1, obj2, **hints):
        """Return whether a relation is allowed between these two models

        We only allow relations between models stored in the same database.
        """
        # I'm not sure of how to correctly implement this method.
        # It was the same for allow_migrate and I made it wrong.

        # However, there is no JOIN relation between two tables of two
        # different db for now. So it seems safe to me to simply allow relation
        # if the tables are in the same db.

        app_model1 = obj1._meta.app_label, obj1._meta.model_name
        app_model2 = obj2._meta.app_label, obj2._meta.model_name
        return _database_to_use.get(app_model1) \
            == _database_to_use.get(app_model2)

    def allow_migrate(self, db, app_label, model_name=None, **hints):
        """
        Allow migration only if the migration is applying to the right db.
        """
        db_to_use = _database_to_use.get((app_label, model_name), 'default')
        if db_to_use != db:
            return False
        using = hints.get('using')
        if using:
            return using == db
        return True
<commit_msg>Use a intermediate get_database function to route the database operations.<commit_after>
_database_to_use = {
    ('search', 'search'): 'transient'
}


def get_database(app_label, model_name, default=None):
    return _database_to_use.get((app_label, model_name), default)


class DatabaseRouter(object):
    """
    A Database router.
    Some models do not need (and must not be backuped).
    So we route them to the transient base.
    """
    def db_for_read(self, model, **hints):
        """
        Return the database from which this model can be read,
        or None to use the default database.
        """
        return get_database(model._meta.app_label, model._meta.model_name)

    def db_for_write(self, model, **hints):
        """
        Return database for which this model can be write,
        or None to use the default database.
        """
        return get_database(model._meta.app_label, model._meta.model_name)

    def allow_relation(self, obj1, obj2, **hints):
        """Return whether a relation is allowed between these two models

        We only allow relations between models stored in the same database.
        """
        # I'm not sure of how to correctly implement this method.
        # It was the same for allow_migrate and I made it wrong.

        # However, there is no JOIN relation between two tables of two
        # different db for now. So it seems safe to me to simply allow relation
        # if the tables are in the same db.
        return get_database(obj1._meta.app_label, obj1._meta.model_name) \
            == get_database(obj2._meta.app_label, obj2._meta.model_name)

    def allow_migrate(self, db, app_label, model_name=None, **hints):
        """
        Allow migration only if the migration is applying to the right db.
        """
        db_to_use = get_database(app_label, model_name, default='default')
        if db_to_use != db:
            return False
        using = hints.get('using')
        if using:
            return using == db
        return True

{'fraction_non_alphanumeric': 0.08215788171244741, 'fraction_numerical': 0.003959415986142044, 'mean_word_length': 2.454700854700855, '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': '3269654', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1128, 'n_words': 417}