mirror of
https://github.com/norohind/SquadsActivityMonitor.git
synced 2026-10-22 17:12:08 +03:00
web: optimization
This commit is contained in:
2 files changed
+18
-3
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user