mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-19 12:59:42 -07:00
Update grouping logic for new sessions
* Check the user's previous row to match the rating key
This commit is contained in:
parent
4fa70cb234
commit
7c725ee424
1 changed files with 22 additions and 15 deletions
|
@ -293,28 +293,35 @@ class MonitorProcessing(object):
|
||||||
# logger.debug(u"PlexPy Monitor :: Writing session_history transaction...")
|
# logger.debug(u"PlexPy Monitor :: Writing session_history transaction...")
|
||||||
self.db.action(query=query, args=args)
|
self.db.action(query=query, args=args)
|
||||||
|
|
||||||
# Check if we should group the session
|
# Check if we should group the session, select the last two rows from the user
|
||||||
query = 'SELECT id, rating_key, user_id, reference_id FROM session_history ORDER BY id DESC LIMIT 2 '
|
query = 'SELECT id, rating_key, user_id, reference_id FROM session_history \
|
||||||
result = self.db.select(query)
|
WHERE user_id = ? ORDER BY id DESC LIMIT 2 '
|
||||||
|
|
||||||
|
args = [session['user_id']]
|
||||||
|
|
||||||
|
result = self.db.select(query=query, args=args)
|
||||||
|
|
||||||
if len(result) == 2:
|
new_session = {'id': result[0][0],
|
||||||
new_session = {'id': result[0][0],
|
'rating_key': result[0][1],
|
||||||
'rating_key': result[0][1],
|
'user_id': result[0][2],
|
||||||
'user_id': result[0][2],
|
'reference_id': result[0][3]}
|
||||||
'reference_id': result[0][3]}
|
|
||||||
|
if len(result) == 1:
|
||||||
|
prev_session = None
|
||||||
|
else:
|
||||||
prev_session = {'id': result[1][0],
|
prev_session = {'id': result[1][0],
|
||||||
'rating_key': result[1][1],
|
'rating_key': result[1][1],
|
||||||
'user_id': result[1][2],
|
'user_id': result[1][2],
|
||||||
'reference_id': result[1][3]}
|
'reference_id': result[1][3]}
|
||||||
|
|
||||||
query = 'UPDATE session_history SET reference_id = ? WHERE id = ? '
|
query = 'UPDATE session_history SET reference_id = ? WHERE id = ? '
|
||||||
# If rating_key and user are the same in the previous session, then set the reference_id to the previous row
|
# If rating_key is the same in the previous session, then set the reference_id to the previous row, else set the reference_id to the new id
|
||||||
if prev_session['rating_key'] == new_session['rating_key'] and prev_session['user_id'] == new_session['user_id']:
|
if (prev_session is not None) and (prev_session['rating_key'] == new_session['rating_key']):
|
||||||
args = [prev_session['reference_id'], new_session['id']]
|
args = [prev_session['reference_id'], new_session['id']]
|
||||||
else:
|
else:
|
||||||
args = [new_session['id'], new_session['id']]
|
args = [new_session['id'], new_session['id']]
|
||||||
|
|
||||||
self.db.action(query=query, args=args)
|
self.db.action(query=query, args=args)
|
||||||
|
|
||||||
# logger.debug(u"PlexPy Monitor :: Successfully written history item, last id for session_history is %s"
|
# logger.debug(u"PlexPy Monitor :: Successfully written history item, last id for session_history is %s"
|
||||||
# % last_id)
|
# % last_id)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue