Skip to content

Commit

Permalink
Reduce recursivity
Browse files Browse the repository at this point in the history
  • Loading branch information
alexiri committed Nov 17, 2024
1 parent db7f230 commit 55802e4
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions outlook/indico_outlook/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class OutlookUserPreferences(ExtraUserPreferences):
'outlook_favorite_categories': BooleanField(_('Sync favorite categories with Outlook'),
[HiddenUnless('extra_outlook_active', preserve_data=True)],
widget=SwitchWidget(),
description=_('Add all events in categories (and all subcategories) I mark as '
description=_('Add all events in categories (and their first-level subcategories) I mark as '
'favorite to my Outlook calendar')),
'outlook_status': SelectField(_('Outlook entry status'),
[HiddenUnless('extra_outlook_active', preserve_data=True)],
Expand Down Expand Up @@ -240,11 +240,13 @@ def event_updated(self, event, changes, **kwargs):
if self._user_tracks_favorite_events(user):
users_to_update.add(user)

# Now look for users that have marked as favorite that event's category (or any of its parents)
for category in event.category.chain_query.all():
for user in category.favorite_of:
if self._user_tracks_favorite_categories(user) and event.can_access(user):
users_to_update.add(user)
# Now look for users that have marked as favorite that event's category (or its parent)
category_favorites = event.category.favorite_of
if event.category.parent:
category_favorites |= event.category.parent.favorite_of
for user in category_favorites:
if self._user_tracks_favorite_categories(user) and event.can_access(user):
users_to_update.add(user)

for user in users_to_update:
self.logger.info('Event data change: updating %s in %r', user, event)
Expand All @@ -271,10 +273,12 @@ def event_deleted(self, event, **kwargs):
for user in event.favorite_of:
if self._user_tracks_favorite_events(user):
users_to_update.add(user)
for category in event.category.chain_query.all():
for user in category.favorite_of:
if self._user_tracks_favorite_categories(user) and event.can_access(user):
users_to_update.add(user)
category_favorites = event.category.favorite_of
if event.category.parent:
category_favorites |= event.category.parent.favorite_of
for user in category_favorites:
if self._user_tracks_favorite_categories(user) and event.can_access(user):
users_to_update.add(user)

for user in users_to_update:
self.logger.info('Event deletion: removing %s in %r', user, event)
Expand All @@ -293,9 +297,11 @@ def _record_change(self, event, user, action):
return
if user in event.favorite_of and self._user_tracks_favorite_events(user):
return
for category in event.category.chain_query.all():
if user in category.favorite_of \
and self._user_tracks_favorite_categories(user) \
category_favorites = event.category.favorite_of
if event.category.parent:
category_favorites |= event.category.parent.favorite_of
for user in category_favorites:
if self._user_tracks_favorite_categories(user) \
and event.can_access(user):
return

Expand Down

0 comments on commit 55802e4

Please sign in to comment.