mirror of
https://gitlab.com/tildes/tildes.git
synced 2026-04-17 06:48:36 +02:00
TopicQuery: include ignored topics by default
Previously, TopicQuery was excluding ignored topics by default. However, this caused some unexpected issues, such as a crash when someone tried to vote on a topic after ignoring it. I think it's more intuitive to reverse the logic like this: include the ignored topics by default, and only specifically exclude them in the cases where that's necessary.
This commit is contained in:
@@ -38,8 +38,7 @@ class TopicQuery(PaginatedQuery):
|
||||
self._only_ignored = False
|
||||
self._only_user_voted = False
|
||||
|
||||
# filter out ignored topics by default for logged-in users
|
||||
self.filter_ignored = bool(request.user)
|
||||
self.filter_ignored = False
|
||||
|
||||
def _attach_extra_data(self) -> "TopicQuery":
|
||||
"""Attach the extra user data to the query."""
|
||||
@@ -59,7 +58,7 @@ class TopicQuery(PaginatedQuery):
|
||||
# pylint: disable=self-cls-assignment
|
||||
self = super()._finalize()
|
||||
|
||||
if self.filter_ignored:
|
||||
if self.filter_ignored and self.request.user:
|
||||
self = self.filter(TopicIgnore.topic_id == None) # noqa
|
||||
|
||||
return self
|
||||
@@ -233,12 +232,11 @@ class TopicQuery(PaginatedQuery):
|
||||
"""Restrict the topics to ones that the user has ignored (generative)."""
|
||||
# pylint: disable=self-cls-assignment
|
||||
self._only_ignored = True
|
||||
self = self.include_ignored()
|
||||
|
||||
return self
|
||||
|
||||
def include_ignored(self) -> "TopicQuery":
|
||||
"""Specify that ignored topics should be included (generative)."""
|
||||
self.filter_ignored = False
|
||||
def exclude_ignored(self) -> "TopicQuery":
|
||||
"""Specify that ignored topics should be excluded (generative)."""
|
||||
self.filter_ignored = True
|
||||
|
||||
return self
|
||||
|
||||
@@ -25,7 +25,6 @@ def topic_by_id36(request: Request, topic_id36: str) -> Topic:
|
||||
request.query(Topic)
|
||||
.include_deleted()
|
||||
.include_removed()
|
||||
.include_ignored()
|
||||
.filter_by(topic_id=topic_id)
|
||||
)
|
||||
|
||||
|
||||
@@ -42,9 +42,6 @@ def get_bookmarks(
|
||||
.order_by(desc(bookmark_cls.created_time))
|
||||
)
|
||||
|
||||
if post_cls == Topic:
|
||||
query = query.include_ignored()
|
||||
|
||||
if before:
|
||||
query = query.before_id36(before)
|
||||
|
||||
|
||||
@@ -215,6 +215,7 @@ def get_group_topics( # noqa
|
||||
request.query(Topic)
|
||||
.join_all_relationships()
|
||||
.inside_groups(groups, include_subgroups=not is_home_page)
|
||||
.exclude_ignored()
|
||||
.apply_sort_option(order)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user