web: optimization

This commit is contained in:
norohind 2022-01-17 01:26:01 +03:00
parent b6f43292eb
commit dd8f2754e9
Signed by: norohind
GPG Key ID: 01C3BECC26FB59E1
2 changed files with 18 additions and 3 deletions

View File

@ -1,5 +1,6 @@
import json
import typing
import datetime
import psycopg2.extensions
import psycopg2.extras
@ -63,6 +64,20 @@ class PostgresModel(AbstractModel):
logger.debug(f'Not cached result for {cache_key}')
if low_timestamp is None and high_timestamp is None and limit is None:
# let's apply an optimization: use yesterday's date as minimal date
high_timestamp = '3307-12-12'
low_timestamp = (datetime.date.today() - datetime.timedelta(days=1)).strftime('%Y-%m-%d')
if low_timestamp is None:
low_timestamp = '0001-01-01'
if high_timestamp is None:
high_timestamp = '3307-12-12'
if limit is None:
limit = 10
with self.db.cursor(cursor_factory=psycopg2.extras.RealDictCursor) as cursor:
cursor.execute(postgres_sql_requests.select_activity_pretty_names, {
'LB_type': utils.LeaderboardTypes(leaderboard_type.lower()).value,

6
web.py
View File

@ -38,9 +38,9 @@ class Activity:
args_activity_changes = {
'platform': platform,
'leaderboard_type': leaderboard,
'limit': req.params.get('limit', 10),
'high_timestamp': req.params.get('before', '3307-12-12'),
'low_timestamp': req.params.get('after', '0001-01-01')
'limit': req.params.get('limit', None),
'high_timestamp': req.params.get('before', None),
'low_timestamp': req.params.get('after', None)
}
try: