2016-08-24 10:28:51 +00:00
|
|
|
import threading
|
2016-04-18 20:41:39 +00:00
|
|
|
import sqlalchemy
|
|
|
|
from szurubooru import config
|
|
|
|
|
2016-08-14 12:22:53 +00:00
|
|
|
|
2016-08-24 10:28:51 +00:00
|
|
|
# pylint: disable=invalid-name
|
|
|
|
_engine = sqlalchemy.create_engine(config.config['database'])
|
2016-08-26 11:43:55 +00:00
|
|
|
sessionmaker = sqlalchemy.orm.sessionmaker(bind=_engine, autoflush=False)
|
2016-08-24 10:28:51 +00:00
|
|
|
session = sqlalchemy.orm.scoped_session(sessionmaker)
|
2016-05-08 17:41:35 +00:00
|
|
|
|
2016-08-24 10:28:51 +00:00
|
|
|
_data = threading.local()
|
2016-05-08 17:41:35 +00:00
|
|
|
|
|
|
|
|
2016-08-24 10:28:51 +00:00
|
|
|
def reset_query_count():
|
|
|
|
_data.query_count = 0
|
2016-05-08 17:41:35 +00:00
|
|
|
|
2016-08-14 12:22:53 +00:00
|
|
|
|
2016-08-24 10:28:51 +00:00
|
|
|
def get_query_count():
|
|
|
|
return _data.query_count
|
|
|
|
|
|
|
|
|
|
|
|
def _bump_query_count():
|
|
|
|
_data.query_count = getattr(_data, 'query_count', 0) + 1
|
|
|
|
|
2016-08-14 18:06:49 +00:00
|
|
|
|
|
|
|
sqlalchemy.event.listen(
|
2016-08-24 10:28:51 +00:00
|
|
|
_engine, 'after_execute', lambda *args: _bump_query_count())
|