mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 07:46:07 -07:00
Improve user delete/purge function
This commit is contained in:
parent
377a23478e
commit
faac6b11c2
6 changed files with 128 additions and 121 deletions
|
@ -58,14 +58,6 @@ def delete_recently_added():
|
|||
return clear_table('recently_added')
|
||||
|
||||
|
||||
def delete_session_history_rows(row_ids=None):
|
||||
if row_ids:
|
||||
for table in ('session_history', 'session_history_media_info', 'session_history_metadata'):
|
||||
delete_rows_from_table(table=table, row_ids=row_ids)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def delete_rows_from_table(table, row_ids):
|
||||
if row_ids and isinstance(row_ids, basestring):
|
||||
row_ids = map(helpers.cast_to_int, row_ids.split(','))
|
||||
|
@ -76,6 +68,26 @@ def delete_rows_from_table(table, row_ids):
|
|||
monitor_db.action(query, row_ids)
|
||||
|
||||
|
||||
def delete_session_history_rows(row_ids=None):
|
||||
if row_ids:
|
||||
for table in ('session_history', 'session_history_media_info', 'session_history_metadata'):
|
||||
delete_rows_from_table(table=table, row_ids=row_ids)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def delete_user_history(user_id=None):
|
||||
if str(user_id).isdigit():
|
||||
monitor_db = MonitorDatabase()
|
||||
|
||||
# Get all history associated with the user_id
|
||||
result = monitor_db.select('SELECT id FROM session_history WHERE user_id = ?', [user_id])
|
||||
row_ids = [row['id'] for row in result]
|
||||
|
||||
logger.info(u"Tautulli Database :: Deleting all history for user id %s from database." % user_id)
|
||||
return delete_session_history_rows(row_ids=row_ids)
|
||||
|
||||
|
||||
def db_filename(filename=FILENAME):
|
||||
""" Returns the filepath to the db """
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue