mirror of
https://github.com/norohind/SquadsActivityMonitor.git
synced 2025-04-13 21:37:12 +03:00
web: optimization
This commit is contained in:
parent
b6f43292eb
commit
dd8f2754e9
@ -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
6
web.py
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user