mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-06 05:01:14 -07:00
Regroup history in separate thread and improve logging
This commit is contained in:
parent
343a3e9281
commit
d91e561a56
3 changed files with 16 additions and 8 deletions
|
@ -2498,9 +2498,9 @@ $(document).ready(function() {
|
|||
});
|
||||
|
||||
$("#regroup_history").click(function () {
|
||||
var msg = 'Are you sure you want to regroup play history in the database?';
|
||||
var msg = 'Are you sure you want to regroup play history in the database?<br /><br /><strong>This make take a long time for large databases.<br />Regrouping will continue in the background.</strong>';
|
||||
var url = 'regroup_history';
|
||||
confirmAjaxCall(url, msg, null, 'Regrouping play history...');
|
||||
confirmAjaxCall(url, msg);
|
||||
});
|
||||
|
||||
$("#delete_temp_sessions").click(function () {
|
||||
|
|
|
@ -719,8 +719,14 @@ class ActivityProcessor(object):
|
|||
"JOIN session_history_metadata ON session_history.id = session_history_metadata.id"
|
||||
)
|
||||
results = self.db.select(query)
|
||||
count = len(results)
|
||||
progress = 0
|
||||
|
||||
for i, session in enumerate(results, start=1):
|
||||
if int(i / count * 10) > progress:
|
||||
progress = int(i / count * 10)
|
||||
logger.info("Tautulli ActivityProcessor :: Regrouping session history: %d%%", progress * 10)
|
||||
|
||||
for session in results:
|
||||
try:
|
||||
self.group_history(session['id'], session)
|
||||
except Exception as e:
|
||||
|
@ -729,3 +735,7 @@ class ActivityProcessor(object):
|
|||
|
||||
logger.info("Tautulli ActivityProcessor :: Regrouping session history complete.")
|
||||
return True
|
||||
|
||||
|
||||
def regroup_history():
|
||||
ActivityProcessor().regroup_history()
|
||||
|
|
|
@ -443,12 +443,10 @@ class WebInterface(object):
|
|||
def regroup_history(self, **kwargs):
|
||||
""" Regroup play history in the database."""
|
||||
|
||||
result = activity_processor.ActivityProcessor().regroup_history()
|
||||
threading.Thread(target=activity_processor.regroup_history).start()
|
||||
|
||||
if result:
|
||||
return {'result': 'success', 'message': 'Regrouped play history.'}
|
||||
else:
|
||||
return {'result': 'error', 'message': 'Regrouping play history failed.'}
|
||||
return {'result': 'success',
|
||||
'message': 'Regrouping play history started. Check the logs to monitor any problems.'}
|
||||
|
||||
@cherrypy.expose
|
||||
@cherrypy.tools.json_out()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue