mirror of
https://github.com/norohind/SquadsActivityMonitor.git
synced 2025-05-31 15:49:21 +03:00
web: optimization
This commit is contained in:
parent
b6f43292eb
commit
dd8f2754e9
@ -1,5 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
import typing
|
import typing
|
||||||
|
import datetime
|
||||||
|
|
||||||
import psycopg2.extensions
|
import psycopg2.extensions
|
||||||
import psycopg2.extras
|
import psycopg2.extras
|
||||||
@ -63,6 +64,20 @@ class PostgresModel(AbstractModel):
|
|||||||
|
|
||||||
logger.debug(f'Not cached result for {cache_key}')
|
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:
|
with self.db.cursor(cursor_factory=psycopg2.extras.RealDictCursor) as cursor:
|
||||||
cursor.execute(postgres_sql_requests.select_activity_pretty_names, {
|
cursor.execute(postgres_sql_requests.select_activity_pretty_names, {
|
||||||
'LB_type': utils.LeaderboardTypes(leaderboard_type.lower()).value,
|
'LB_type': utils.LeaderboardTypes(leaderboard_type.lower()).value,
|
||||||
|
6
web.py
6
web.py
@ -38,9 +38,9 @@ class Activity:
|
|||||||
args_activity_changes = {
|
args_activity_changes = {
|
||||||
'platform': platform,
|
'platform': platform,
|
||||||
'leaderboard_type': leaderboard,
|
'leaderboard_type': leaderboard,
|
||||||
'limit': req.params.get('limit', 10),
|
'limit': req.params.get('limit', None),
|
||||||
'high_timestamp': req.params.get('before', '3307-12-12'),
|
'high_timestamp': req.params.get('before', None),
|
||||||
'low_timestamp': req.params.get('after', '0001-01-01')
|
'low_timestamp': req.params.get('after', None)
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user