Browse Source

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.
merge-requests/106/head
Deimos 5 years ago
parent
commit
740f71d339
  1. 12
      tildes/tildes/models/topic/topic_query.py
  2. 1
      tildes/tildes/resources/topic.py
  3. 3
      tildes/tildes/views/bookmarks.py
  4. 1
      tildes/tildes/views/topic.py

12
tildes/tildes/models/topic/topic_query.py

@ -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

1
tildes/tildes/resources/topic.py

@ -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)
)

3
tildes/tildes/views/bookmarks.py

@ -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)

1
tildes/tildes/views/topic.py

@ -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)
)

Loading…
Cancel
Save