Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Optimize last activity helper

Roland Geider0c6a6f933a37
diff --git a/wger/gym/helpers.py b/wger/gym/helpers.py
index ea6f0148c..c55b5922c 100644
--- a/wger/gym/helpers.py
+++ b/wger/gym/helpers.py
@@ -26,16 +26,20 @@ def get_user_last_activity(user):
:return: a date or None if nothing was found
'''
- # Check workout logs
- log_list = WorkoutLog.objects.filter(user=user).order_by('date')
last_activity = None
- if log_list.exists():
- last_activity = log_list.last().date
+
+ # Check workout logs
+ last_log = WorkoutLog.objects.filter(user=user).order_by('date').last()
+ if last_log:
+ last_activity = last_log.date
# Check workout sessions
- log_session = WorkoutSession.objects.filter(user=user).order_by('date')
- if log_session.exists():
- last_session = log_session.last().date
+ last_session = WorkoutSession.objects.filter(user=user).order_by('date').last()
+ if last_session:
+ last_session = last_session.date
+
+ # Return the last one
+ if last_session:
if not last_activity:
last_activity = last_session