mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 15:32:38 -07:00
Attempt at fixing stuck sessions which require flishing the database
This commit is contained in:
parent
446170f8de
commit
32b43202c2
3 changed files with 25 additions and 22 deletions
|
@ -155,7 +155,12 @@ class ActivityProcessor(object):
|
|||
|
||||
# Reload json from raw stream info
|
||||
if session.get('raw_stream_info'):
|
||||
session.update(json.loads(session['raw_stream_info']))
|
||||
raw_stream_info = json.loads(session['raw_stream_info'])
|
||||
# Don't overwrite id, session_key, stopped
|
||||
raw_stream_info.pop('id', None)
|
||||
raw_stream_info.pop('session_key', None)
|
||||
raw_stream_info.pop('stopped', None)
|
||||
session.update(raw_stream_info)
|
||||
|
||||
session = defaultdict(str, session)
|
||||
|
||||
|
@ -177,6 +182,7 @@ class ActivityProcessor(object):
|
|||
else:
|
||||
logger.debug(u"Tautulli ActivityProcessor :: ratingKey %s not logged. Does not meet logging criteria. "
|
||||
u"Media type is '%s'" % (session['rating_key'], session['media_type']))
|
||||
return session['id']
|
||||
|
||||
if str(session['paused_counter']).isdigit():
|
||||
real_play_time = stopped - session['started'] - int(session['paused_counter'])
|
||||
|
@ -284,7 +290,7 @@ class ActivityProcessor(object):
|
|||
|
||||
query = 'UPDATE session_history SET reference_id = ? WHERE id = ? '
|
||||
# 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 == new_session == None:
|
||||
if prev_session is None and new_session is None:
|
||||
args = [last_id, last_id]
|
||||
elif prev_session['rating_key'] == new_session['rating_key'] and prev_session['view_offset'] <= new_session['view_offset']:
|
||||
args = [prev_session['reference_id'], new_session['id']]
|
||||
|
@ -414,8 +420,8 @@ class ActivityProcessor(object):
|
|||
# logger.debug(u"Tautulli ActivityProcessor :: Writing session_history_metadata transaction...")
|
||||
self.db.upsert(table_name='session_history_metadata', key_dict=keys, value_dict=values)
|
||||
|
||||
# Return true when the session is successfully written to the database
|
||||
return True
|
||||
# Return the session row id when the session is successfully written to the database
|
||||
return session['id']
|
||||
|
||||
def get_sessions(self, user_id=None, ip_address=None):
|
||||
query = 'SELECT * FROM sessions'
|
||||
|
@ -456,9 +462,11 @@ class ActivityProcessor(object):
|
|||
|
||||
return None
|
||||
|
||||
def delete_session(self, session_key=None):
|
||||
def delete_session(self, session_key=None, row_id=None):
|
||||
if str(session_key).isdigit():
|
||||
self.db.action('DELETE FROM sessions WHERE session_key = ?', [session_key])
|
||||
elif str(row_id).isdigit():
|
||||
self.db.action('DELETE FROM sessions WHERE id = ?', [row_id])
|
||||
|
||||
def set_session_last_paused(self, session_key=None, timestamp=None):
|
||||
if str(session_key).isdigit():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue