mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-19 12:59:42 -07:00
Optimize user watch time query
This commit is contained in:
parent
dca5a534fd
commit
7442e53c6c
1 changed files with 5 additions and 2 deletions
|
@ -22,6 +22,7 @@ from future.builtins import object
|
||||||
from future.moves.urllib.parse import parse_qsl
|
from future.moves.urllib.parse import parse_qsl
|
||||||
|
|
||||||
import httpagentparser
|
import httpagentparser
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
import plexpy
|
import plexpy
|
||||||
if plexpy.PYTHON2:
|
if plexpy.PYTHON2:
|
||||||
|
@ -499,6 +500,8 @@ class Users(object):
|
||||||
group_by = 'reference_id' if grouping else 'id'
|
group_by = 'reference_id' if grouping else 'id'
|
||||||
|
|
||||||
for days in query_days:
|
for days in query_days:
|
||||||
|
timestamp = int((datetime.now(tz=plexpy.SYS_TIMEZONE) - timedelta(days=days)).timestamp())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if days > 0:
|
if days > 0:
|
||||||
if str(user_id).isdigit():
|
if str(user_id).isdigit():
|
||||||
|
@ -506,8 +509,8 @@ class Users(object):
|
||||||
' SUM(CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END)) AS total_time, ' \
|
' SUM(CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END)) AS total_time, ' \
|
||||||
'COUNT(DISTINCT %s) AS total_plays ' \
|
'COUNT(DISTINCT %s) AS total_plays ' \
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
|
'WHERE stopped >= %s ' \
|
||||||
'AND user_id = ? ' % (group_by, days)
|
'AND user_id = ? ' % (group_by, timestamp)
|
||||||
result = monitor_db.select(query, args=[user_id])
|
result = monitor_db.select(query, args=[user_id])
|
||||||
else:
|
else:
|
||||||
result = []
|
result = []
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue