Skip to content

Commit

Permalink
Don't delete the routine structure cache when updating logs
Browse files Browse the repository at this point in the history
Logs aren't used to compute the structure
  • Loading branch information
rolandgeider committed Feb 21, 2025
1 parent afc250a commit 6f97feb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 4 additions & 2 deletions wger/manager/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,17 @@ def render_workout_day(
return KeepTogether(t)


def reset_routine_cache(instance: Routine):
def reset_routine_cache(instance: Routine, structure: bool = True):
"""Resets all caches related to a routine"""

cache.delete(CacheKeyMapper.routine_date_sequence_key(instance.id))
cache.delete(CacheKeyMapper.routine_api_date_sequence_display_key(instance.id))
cache.delete(CacheKeyMapper.routine_api_date_sequence_gym_key(instance.id))
cache.delete(CacheKeyMapper.routine_api_structure_key(instance.id))
cache.delete(CacheKeyMapper.routine_api_stats(instance.id))

if structure:
cache.delete(CacheKeyMapper.routine_api_structure_key(instance.id))

if instance.pk:
for day in instance.days.all():
for slot in day.slots.all():
Expand Down
3 changes: 1 addition & 2 deletions wger/manager/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# You should have received a copy of the GNU Affero General Public License

# Django
from django.core.cache import cache
from django.db.models.signals import (
post_save,
pre_delete,
Expand Down Expand Up @@ -77,7 +76,7 @@ def handle_config_change(sender, instance: AbstractChangeConfig, **kwargs):

def update_cache_log(sender, instance: WorkoutLog, **kwargs):
if instance.routine:
reset_routine_cache(instance.routine)
reset_routine_cache(instance.routine, structure=False)


post_save.connect(update_activity_cache, sender=WorkoutSession)
Expand Down

0 comments on commit 6f97feb

Please sign in to comment.