remove caching

This commit is contained in:
Frederik Jaeckel 2023-12-23 10:36:58 +01:00
parent d2ad96db35
commit 9ef465f40f
5 changed files with 10 additions and 258 deletions

41
book.py
View file

@ -12,22 +12,12 @@ from trytond.i18n import gettext
from trytond.transaction import Transaction
from trytond.pool import Pool
from trytond.report import Report
from trytond.config import config
from decimal import Decimal
from datetime import date
from sql.aggregate import Sum
from sql.conditionals import Case
from .model import order_name_hierarchical, sub_ids_hierarchical, \
AnyInArray, CACHEKEY_CURRENCY
# enable/disable caching of cachekey for 'currency.rate'
if config.get(
'cashbook', 'cache_currency', default='yes'
).lower() in ['yes', '1', 'true']:
ENA_CURRKEY = True
else:
ENA_CURRKEY = False
from .model import (
order_name_hierarchical, sub_ids_hierarchical, AnyInArray)
STATES = {
@ -402,7 +392,6 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
Currency = pool.get('currency.currency')
Company = pool.get('company.company')
IrDate = pool.get('ir.date')
MemCache = pool.get('cashbook.memcache')
tab_book = Book2.__table__()
tab_comp = Company.__table__()
cursor = Transaction().connection.cursor()
@ -420,28 +409,6 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
except Exception:
query_date = IrDate.today()
cache_keys = {
x.id: MemCache.get_key_by_record(
name='get_balance_cashbook',
record=x,
query=[{
'model': 'cashbook.line',
'query': [('cashbook.parent', 'child_of', [x.id])],
}, {
'model': 'currency.currency.rate',
'query': [('currency.id', '=', x.currency.id)],
'cachekey' if ENA_CURRKEY
else 'disabled': CACHEKEY_CURRENCY % x.currency.id,
}, ],
addkeys=[query_date.isoformat()])
for x in cashbooks}
# read from cache
(todo_cashbook, result) = MemCache.read_from_cache(
cashbooks, cache_keys, names, result)
if len(todo_cashbook) == 0:
return result
# query balances of cashbooks and sub-cashbooks
with Transaction().set_context({
'date': query_date}):
@ -466,7 +433,7 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
Sum(tab_line.balance_all).as_('balance_all'),
group_by=[
tab_book.id, tab_line.currency, tab_comp.currency],
where=tab_book.id.in_([x.id for x in todo_cashbook]),
where=tab_book.id.in_([x.id for x in cashbooks]),
)
cursor.execute(*query)
records = cursor.fetchall()
@ -478,8 +445,6 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
record[2], record[5], record[1])
result['balance_ref'][record[0]] += Currency.compute(
record[2], record[5], record[3])
MemCache.store_result(cashbooks, cache_keys, result, todo_cashbook)
return result
@fields.depends('btype')