diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html
index 7cd614e0..c5d8fe37 100644
--- a/data/interfaces/default/settings.html
+++ b/data/interfaces/default/settings.html
@@ -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?
This make take a long time for large databases.
Regrouping will continue in the background.';
var url = 'regroup_history';
- confirmAjaxCall(url, msg, null, 'Regrouping play history...');
+ confirmAjaxCall(url, msg);
});
$("#delete_temp_sessions").click(function () {
diff --git a/plexpy/activity_processor.py b/plexpy/activity_processor.py
index b1558a56..0437d2d5 100644
--- a/plexpy/activity_processor.py
+++ b/plexpy/activity_processor.py
@@ -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()
diff --git a/plexpy/webserve.py b/plexpy/webserve.py
index 7549aefa..b98c9e7c 100644
--- a/plexpy/webserve.py
+++ b/plexpy/webserve.py
@@ -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()