Skip to content

Commit

Permalink
Improve statistics query performance
Browse files Browse the repository at this point in the history
The improvement is only 2x which is still quite slow but better than
nothing.
  • Loading branch information
flofriday committed Nov 19, 2023
1 parent 36febaf commit 6779e29
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ def get_chart_data(db: Connection) -> list[Tuple[str, int]]:
COUNT(DISTINCT token_hash) AS 'daily',
(SELECT COUNT(DISTINCT token_hash)
FROM statistics s2
WHERE Date(s2.date) <= Date(s.date) AND Date(s2.date) >= DATE( s.date, '-30 days')
WHERE Date(s2.date) <= s.date AND s2.date >= DATE( s.date, '-30 days')
) AS 'monbthly',
(SELECT COUNT(DISTINCT token_hash)
FROM statistics s3
WHERE Date(s3.date) <= Date(s.date)
WHERE Date(s3.date) <= s.date
) AS 'total'
FROM statistics s
GROUP BY day
ORDER BY day
ORDER BY day
"""
)
rows = cursor.fetchall()
Expand Down

0 comments on commit 6779e29

Please sign in to comment.