# HG changeset patch # User neko259 # Date 2017-12-18 16:27:21 # Node ID dcf7666c554fa96e612debf762da3694eb79d6ad # Parent ef4735f5fad3a75ab2c6cc473d1b07f7821a92f8 Do not load fav tags when need to only check notifications diff --git a/boards/abstracts/settingsmanager.py b/boards/abstracts/settingsmanager.py --- a/boards/abstracts/settingsmanager.py +++ b/boards/abstracts/settingsmanager.py @@ -241,6 +241,9 @@ class DatabaseSettingsManager(SessionSet def tag_is_hidden(self, tag): return self.settings.hidden_tags.filter(id=tag.id).exists() + def get_user_settings(self): + return self.settings + def get_settings_manager(request) -> SettingsManager: """ diff --git a/boards/context_processors.py b/boards/context_processors.py --- a/boards/context_processors.py +++ b/boards/context_processors.py @@ -34,7 +34,7 @@ def get_notifications(context, settings_ SETTING_LAST_NOTIFICATION_ID) new_notifications_count = Notification.objects.get_notification_posts( - usernames=usernames, last=last_notification_id, fav_tags=fav_tags).only('id').count() + usernames=usernames, last=last_notification_id, user_settings=settings_manager.get_user_settings()).count() context[CONTEXT_NEW_NOTIFICATIONS_COUNT] = new_notifications_count context[CONTEXT_USERNAMES] = usernames diff --git a/boards/models/user.py b/boards/models/user.py --- a/boards/models/user.py +++ b/boards/models/user.py @@ -25,11 +25,11 @@ class Ban(models.Model): class NotificationManager(models.Manager): - def get_notification_posts(self, usernames: list, last: int = None, fav_tags=None): + def get_notification_posts(self, usernames: list, last: int = None, user_settings=None): lower_names = [username.lower() for username in usernames] posts = boards.models.post.Post.objects.filter( Q(notification__name__in=lower_names) | - (Q(thread__tags__in=fav_tags) & Q(opening=True))).distinct() + (Q(thread__tags__settings_as_fav=user_settings) & Q(opening=True))).distinct() if last is not None: posts = posts.filter(id__gt=last) posts = posts.order_by('-id') diff --git a/boards/views/notifications.py b/boards/views/notifications.py --- a/boards/views/notifications.py +++ b/boards/views/notifications.py @@ -27,10 +27,8 @@ class NotificationView(BaseBoardView): else: notification_usernames = [username] - fav_tags = settings_manager.get_fav_tags() - posts = Notification.objects.get_notification_posts( - usernames=notification_usernames, fav_tags=fav_tags) + usernames=notification_usernames, user_settings=settings_manager.get_user_settings()) if username is None: last = posts.first()