asset/rate: speed up percent-queries
This commit is contained in:
parent
3b9de6c0bb
commit
38e2c34a53
2 changed files with 29 additions and 26 deletions
16
asset.py
16
asset.py
|
@ -473,8 +473,6 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
||||||
"""
|
"""
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
Rate = pool.get('investment.rate')
|
Rate = pool.get('investment.rate')
|
||||||
Asset2 = pool.get('investment.asset')
|
|
||||||
tab_asset = Asset2.__table__()
|
|
||||||
tab_rate1 = Rate.__table__()
|
tab_rate1 = Rate.__table__()
|
||||||
tab_rate2 = Rate.__table__()
|
tab_rate2 = Rate.__table__()
|
||||||
context = Transaction().context
|
context = Transaction().context
|
||||||
|
@ -482,17 +480,14 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
||||||
query_date = context.get('qdate', CurrentDate())
|
query_date = context.get('qdate', CurrentDate())
|
||||||
where_asset = tab_rate1.date <= query_date
|
where_asset = tab_rate1.date <= query_date
|
||||||
if isinstance(asset_ids, list):
|
if isinstance(asset_ids, list):
|
||||||
where_asset &= tab_asset.id.in_(asset_ids)
|
where_asset &= tab_rate1.asset.in_(asset_ids)
|
||||||
|
|
||||||
tab_today = tab_asset.join(
|
tab_today = tab_rate1.select(
|
||||||
tab_rate1,
|
tab_rate1.asset.as_('id'),
|
||||||
condition=tab_asset.id == tab_rate1.asset,
|
|
||||||
).select(
|
|
||||||
tab_asset.id,
|
|
||||||
tab_rate1.date,
|
tab_rate1.date,
|
||||||
tab_rate1.rate,
|
tab_rate1.rate,
|
||||||
distinct_on=[tab_asset.id],
|
distinct_on=[tab_rate1.asset],
|
||||||
order_by=[tab_asset.id, tab_rate1.date.desc],
|
order_by=[tab_rate1.asset, tab_rate1.date.desc],
|
||||||
where=where_asset,
|
where=where_asset,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -613,6 +608,7 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
||||||
exp = Decimal(Decimal(1) / 10 ** digits_percent)
|
exp = Decimal(Decimal(1) / 10 ** digits_percent)
|
||||||
asset_id_lst = [x.id for x in assets]
|
asset_id_lst = [x.id for x in assets]
|
||||||
|
|
||||||
|
if asset_id_lst and names:
|
||||||
for x in names:
|
for x in names:
|
||||||
tab_percent = cls.get_percentage_sql(
|
tab_percent = cls.get_percentage_sql(
|
||||||
days={
|
days={
|
||||||
|
|
7
rate.py
7
rate.py
|
@ -53,6 +53,13 @@ class Rate(SymbolMixin, ModelSQL, ModelView):
|
||||||
Index(
|
Index(
|
||||||
t,
|
t,
|
||||||
(t.rate, Index.Range())),
|
(t.rate, Index.Range())),
|
||||||
|
Index(
|
||||||
|
t,
|
||||||
|
(t.asset, Index.Equality())),
|
||||||
|
Index(
|
||||||
|
t,
|
||||||
|
(t.asset, Index.Equality()),
|
||||||
|
(t.date, Index.Range(order='DESC'))),
|
||||||
})
|
})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Reference in a new issue