<commit_before>import abc
import uuid
import struct
import weakref

from bson import json_util, EPOCH_NAIVE
# Monkeypatch to not include tz_info in decoded JSON.
# Kind of a ridiculous solution, but works.
json_util.EPOCH_AWARE = EPOCH_NAIVE

from sqlalchemy import String, Text, event
from sqlalchemy.types import TypeDecorator, BINARY
from sqlalchemy.interfaces import PoolListener
from sqlalchemy.engine import Engine
from sqlalchemy.ext import baked
from sqlalchemy.ext.mutable import Mutable
from sqlalchemy.ext.declarative import DeclarativeMeta

from inbox.util.encoding import base36encode, base36decode

from nylas.logging import get_logger
log = get_logger()


MAX_SANE_QUERIES_PER_SESSION = 100
MAX_TEXT_LENGTH = 65535

# Automatically bake queries for lazily-loaded relationships.
# Lazy loads are often suboptimal, but this makes them less so!
baked.bake_lazy_loaders()

bakery = baked.bakery(size=1024)


query_counts = weakref.WeakKeyDictionary()


@event.listens_for(Engine, "before_cursor_execute")
def before_cursor_execute(conn, cursor, statement,
                          parameters, context, executemany):
    if conn not in query_counts:
        query_counts[conn] = 1
    else:
        query_counts[conn] += 1


@event.listens_for(Engine, 'commit')
def before_commit(conn):
    if query_counts.get(conn, 0) > MAX_SANE_QUERIES_PER_SESSION:
        log.warning('Dubiously many queries per session!',
                    query_count=query_counts.get(conn))


class SQLAlchemyCompatibleAbstractMetaClass(DeclarativeMeta, abc.ABCMeta):<commit_msg>Revert "Call SQLAlchemy's bake_lazy_loaders() for performance."<commit_after>import abc
import uuid
import struct
import weakref

from bson import json_util, EPOCH_NAIVE
# Monkeypatch to not include tz_info in decoded JSON.
# Kind of a ridiculous solution, but works.
json_util.EPOCH_AWARE = EPOCH_NAIVE

from sqlalchemy import String, Text, event
from sqlalchemy.types import TypeDecorator, BINARY
from sqlalchemy.interfaces import PoolListener
from sqlalchemy.engine import Engine
from sqlalchemy.ext import baked
from sqlalchemy.ext.mutable import Mutable
from sqlalchemy.ext.declarative import DeclarativeMeta

from inbox.util.encoding import base36encode, base36decode

from nylas.logging import get_logger
log = get_logger()


MAX_SANE_QUERIES_PER_SESSION = 100
MAX_TEXT_LENGTH = 65535


bakery = baked.bakery()


query_counts = weakref.WeakKeyDictionary()


@event.listens_for(Engine, "before_cursor_execute")
def before_cursor_execute(conn, cursor, statement,
                          parameters, context, executemany):
    if conn not in query_counts:
        query_counts[conn] = 1
    else:
        query_counts[conn] += 1


@event.listens_for(Engine, 'commit')
def before_commit(conn):
    if query_counts.get(conn, 0) > MAX_SANE_QUERIES_PER_SESSION:
        log.warning('Dubiously many queries per session!',
                    query_count=query_counts.get(conn))


class SQLAlchemyCompatibleAbstractMetaClass(DeclarativeMeta, abc.ABCMeta):
{'fraction_non_alphanumeric': 0.06818934127772261, 'fraction_numerical': 0.011254551473022179, 'mean_word_length': 4.789272030651341, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7459189', 'n_tokens_mistral': 1020, 'n_tokens_neox': 948, 'n_words': 254}