mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-22 14:13:40 -07:00
update API and datafactory optimizations
This commit is contained in:
parent
cff3a4153c
commit
fa5fa7f2e1
2 changed files with 32 additions and 23 deletions
|
@ -1157,7 +1157,7 @@ class DataFactory(object):
|
|||
group_by = 'session_history.reference_id' if grouping else 'session_history.id'
|
||||
|
||||
_rating_keys = []
|
||||
if media_type and media_type == 'collection':
|
||||
if media_type == 'collection':
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
result = pms_connect.get_item_children(rating_key=rating_key)
|
||||
|
||||
|
@ -1166,7 +1166,8 @@ class DataFactory(object):
|
|||
else:
|
||||
_rating_keys.append(rating_key)
|
||||
|
||||
rating_keys = '(' + ','.join(_rating_keys) + ')'
|
||||
rating_keys = ','.join(_rating_keys)
|
||||
rating_keys_arg = ','.join(['?'] * len(rating_keys))
|
||||
|
||||
for days in query_days:
|
||||
timestamp_query = timestamp - days * 24 * 60 * 60
|
||||
|
@ -1179,12 +1180,13 @@ class DataFactory(object):
|
|||
'COUNT(DISTINCT %s) AS total_plays, section_id ' \
|
||||
'FROM session_history ' \
|
||||
'JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \
|
||||
'WHERE stopped >= %s ' \
|
||||
'AND (session_history.grandparent_rating_key IN %s ' \
|
||||
'OR session_history.parent_rating_key IN %s ' \
|
||||
'OR session_history.rating_key IN %s)' % (group_by, timestamp_query,
|
||||
rating_keys, rating_keys, rating_keys)
|
||||
result = monitor_db.select(query)
|
||||
'WHERE stopped >= ? ' \
|
||||
'AND (session_history.grandparent_rating_key IN (%s) ' \
|
||||
'OR session_history.parent_rating_key IN (%s) ' \
|
||||
'OR session_history.rating_key IN (%s))' % (
|
||||
group_by, rating_keys_arg, rating_keys_arg, rating_keys_arg
|
||||
)
|
||||
result = monitor_db.select(query, args=[timestamp_query, rating_keys, rating_keys, rating_keys])
|
||||
else:
|
||||
result = []
|
||||
else:
|
||||
|
@ -1194,10 +1196,12 @@ class DataFactory(object):
|
|||
'COUNT(DISTINCT %s) AS total_plays, section_id ' \
|
||||
'FROM session_history ' \
|
||||
'JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \
|
||||
'WHERE (session_history.grandparent_rating_key IN %s ' \
|
||||
'OR session_history.parent_rating_key IN %s ' \
|
||||
'OR session_history.rating_key IN %s)' % (group_by, rating_keys, rating_keys, rating_keys)
|
||||
result = monitor_db.select(query)
|
||||
'WHERE (session_history.grandparent_rating_key IN (%s) ' \
|
||||
'OR session_history.parent_rating_key IN (%s) ' \
|
||||
'OR session_history.rating_key IN (%s))' % (
|
||||
group_by, rating_keys_arg, rating_keys_arg, rating_keys_arg
|
||||
)
|
||||
result = monitor_db.select(query, args=[rating_keys, rating_keys, rating_keys])
|
||||
else:
|
||||
result = []
|
||||
except Exception as e:
|
||||
|
@ -1239,7 +1243,7 @@ class DataFactory(object):
|
|||
group_by = 'session_history.reference_id' if grouping else 'session_history.id'
|
||||
|
||||
_rating_keys = []
|
||||
if media_type and media_type == 'collection':
|
||||
if media_type == 'collection':
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
result = pms_connect.get_item_children(rating_key=rating_key)
|
||||
|
||||
|
@ -1248,7 +1252,8 @@ class DataFactory(object):
|
|||
else:
|
||||
_rating_keys.append(rating_key)
|
||||
|
||||
rating_keys = '(' + ','.join(_rating_keys) + ')'
|
||||
rating_keys = ','.join(_rating_keys)
|
||||
rating_keys_arg = ','.join(['?'] * len(rating_keys))
|
||||
|
||||
try:
|
||||
if str(rating_key).isdigit():
|
||||
|
@ -1261,12 +1266,14 @@ class DataFactory(object):
|
|||
'FROM session_history ' \
|
||||
'JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \
|
||||
'JOIN users ON users.user_id = session_history.user_id ' \
|
||||
'WHERE (session_history.grandparent_rating_key IN %s ' \
|
||||
'OR session_history.parent_rating_key IN %s ' \
|
||||
'OR session_history.rating_key IN %s) ' \
|
||||
'WHERE (session_history.grandparent_rating_key IN (%s) ' \
|
||||
'OR session_history.parent_rating_key IN (%s) ' \
|
||||
'OR session_history.rating_key IN (%s)) ' \
|
||||
'GROUP BY users.user_id ' \
|
||||
'ORDER BY total_plays DESC, total_time DESC' % (group_by, rating_keys, rating_keys, rating_keys)
|
||||
result = monitor_db.select(query)
|
||||
'ORDER BY total_plays DESC, total_time DESC' % (
|
||||
group_by, rating_keys_arg, rating_keys_arg, rating_keys_arg
|
||||
)
|
||||
result = monitor_db.select(query, args=[rating_keys, rating_keys, rating_keys])
|
||||
else:
|
||||
result = []
|
||||
except Exception as e:
|
||||
|
|
|
@ -4463,7 +4463,7 @@ class WebInterface(object):
|
|||
@cherrypy.tools.json_out()
|
||||
@requireAuth(member_of("admin"))
|
||||
@addtoapi()
|
||||
def get_item_watch_time_stats(self, rating_key=None, grouping=None, query_days=None, **kwargs):
|
||||
def get_item_watch_time_stats(self, rating_key=None, media_type=None, grouping=None, query_days=None, **kwargs):
|
||||
""" Get the watch time stats for the media item.
|
||||
|
||||
```
|
||||
|
@ -4471,6 +4471,7 @@ class WebInterface(object):
|
|||
rating_key (str): Rating key of the item
|
||||
|
||||
Optional parameters:
|
||||
media_type(str): Media type of the item (only required for a collection)
|
||||
grouping (int): 0 or 1
|
||||
query_days (str): Comma separated days, e.g. "1,7,30,0"
|
||||
|
||||
|
@ -4504,7 +4505,7 @@ class WebInterface(object):
|
|||
|
||||
if rating_key:
|
||||
item_data = datafactory.DataFactory()
|
||||
result = item_data.get_watch_time_stats(rating_key=rating_key, grouping=grouping,
|
||||
result = item_data.get_watch_time_stats(rating_key=rating_key, media_type=media_type, grouping=grouping,
|
||||
query_days=query_days)
|
||||
if result:
|
||||
return result
|
||||
|
@ -4518,7 +4519,7 @@ class WebInterface(object):
|
|||
@cherrypy.tools.json_out()
|
||||
@requireAuth(member_of("admin"))
|
||||
@addtoapi()
|
||||
def get_item_user_stats(self, rating_key=None, grouping=None, **kwargs):
|
||||
def get_item_user_stats(self, rating_key=None, media_type=None, grouping=None, **kwargs):
|
||||
""" Get the user stats for the media item.
|
||||
|
||||
```
|
||||
|
@ -4526,6 +4527,7 @@ class WebInterface(object):
|
|||
rating_key (str): Rating key of the item
|
||||
|
||||
Optional parameters:
|
||||
media_type(str): Media type of the item (only required for a collection)
|
||||
grouping (int): 0 or 1
|
||||
|
||||
Returns:
|
||||
|
@ -4554,7 +4556,7 @@ class WebInterface(object):
|
|||
|
||||
if rating_key:
|
||||
item_data = datafactory.DataFactory()
|
||||
result = item_data.get_user_stats(rating_key=rating_key, grouping=grouping)
|
||||
result = item_data.get_user_stats(rating_key=rating_key, media_type=media_type, grouping=grouping)
|
||||
if result:
|
||||
return result
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue