<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from magpie.constants import get_constant
from magpie.common import get_settings_from_config_ini, print_log, raise_log, get_logger
from magpie.definitions.alembic_definitions import alembic
from magpie.definitions.sqlalchemy_definitions import (
    register, sessionmaker, engine_from_config, ZopeTransactionExtension,
    configure_mappers, select, Inspector, Session, sa_exc
)
from typing import TYPE_CHECKING
import transaction
import inspect
import warnings
import logging
import time

# import or define all models here to ensure they are attached to the
# Base.metadata prior to any initialization routines
from magpie import models

if TYPE_CHECKING:
    from magpie.definitions.typedefs import Str, SettingsType, Optional, Union


LOGGER = get_logger(__name__)

# run configure_mappers after defining all of the models to ensure
# all relationships can be setup
configure_mappers()


def get_db_url(username=None, password=None, db_host=None, db_port=None, db_name=None, settings=None):
    return "postgresql://%s:%s@%s:%s/%s" % (
        username if username is not None else get_constant('MAGPIE_POSTGRES_USER', settings, 'postgres.user'),
        password if password is not None else get_constant('MAGPIE_POSTGRES_PASSWORD', settings, 'postgres.password'),
        db_host if db_host is not None else get_constant('MAGPIE_POSTGRES_HOST', settings, 'postgres.host'),
        db_port if db_port is not None else get_constant('MAGPIE_POSTGRES_PORT', settings, 'postgres.port'),
        db_name if db_name is not None else get_constant('MAGPIE_POSTGRES_DB', settings, 'postgres.db'),
    )


def get_engine(settings, prefix='sqlalchemy.'):
    settings[prefix + 'url'] = get_db_url()
    settings[prefix + 'pool_size'] = 20
    settings[prefix + 'max_overflow'] = 100
    return engine_from_config(settings, prefix)


def get_session_factory(engine):
    factory = sessionmaker(extension=ZopeTransactionExtension())
    factory.configure(bind=engine)
    return factory<commit_msg>Change sqlalchemy engine creation default values:<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from magpie.constants import get_constant
from magpie.common import get_settings_from_config_ini, print_log, raise_log, get_logger
from magpie.definitions.alembic_definitions import alembic
from magpie.definitions.sqlalchemy_definitions import (
    register, sessionmaker, engine_from_config, ZopeTransactionExtension,
    configure_mappers, select, Inspector, Session, sa_exc
)
from typing import TYPE_CHECKING
import transaction
import inspect
import warnings
import logging
import time

# import or define all models here to ensure they are attached to the
# Base.metadata prior to any initialization routines
from magpie import models

if TYPE_CHECKING:
    from magpie.definitions.typedefs import Str, SettingsType, Optional, Union


LOGGER = get_logger(__name__)

# run configure_mappers after defining all of the models to ensure
# all relationships can be setup
configure_mappers()


def get_db_url(username=None, password=None, db_host=None, db_port=None, db_name=None, settings=None):
    return "postgresql://%s:%s@%s:%s/%s" % (
        username if username is not None else get_constant('MAGPIE_POSTGRES_USER', settings, 'postgres.user'),
        password if password is not None else get_constant('MAGPIE_POSTGRES_PASSWORD', settings, 'postgres.password'),
        db_host if db_host is not None else get_constant('MAGPIE_POSTGRES_HOST', settings, 'postgres.host'),
        db_port if db_port is not None else get_constant('MAGPIE_POSTGRES_PORT', settings, 'postgres.port'),
        db_name if db_name is not None else get_constant('MAGPIE_POSTGRES_DB', settings, 'postgres.db'),
    )


def get_engine(settings, prefix='sqlalchemy.'):
    settings[prefix + 'url'] = get_db_url()
    settings[prefix + 'pool_pre_ping'] = settings.get(prefix + 'pool_pre_ping', True)
    return engine_from_config(settings, prefix)


def get_session_factory(engine):
    factory = sessionmaker(extension=ZopeTransactionExtension())
    factory.configure(bind=engine)
    return factory
{'fraction_non_alphanumeric': 0.08594881699661999, 'fraction_numerical': 0.0016900048285852245, 'mean_word_length': 5.443234836702955, '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': '595834', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1211, 'n_words': 355}