This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Do not consider events by ignored users for bundled aggregations #12235
Merged
+427
−45
Merged
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
75b1b5f
Filter out events from ignored users in /relations.
clokep 3a51cfe
Add tests for ignored users in bundled aggregations.
clokep 5e73a5e
Filter out ignored users for aggregation groups.
clokep 56dd70a
Rename a variable.
clokep 3357181
Filter out ignored users for threads.
clokep 9eef5cb
Filter out ignored users for references.
clokep 156ef7a
Add a note about edits.
clokep 3bb8071
Newsfragment
clokep 89c89df
Merge remote-tracking branch 'origin/develop' into clokep/ignored-use…
clokep fffa6ca
Merge remote-tracking branch 'origin/develop' into clokep/ignored-use…
clokep 887fcb0
Merge remote-tracking branch 'origin/develop' into clokep/ignored-use…
clokep fc7d14b
Merge remote-tracking branch 'origin/develop' into clokep/ignored-use…
clokep ecae2ad
Do not cache on the ignored users parameter when fetching relations.
clokep f03a6a8
Newsfragment
clokep 622b621
Do not cache on the ignored users parameter when fetching annotations.
clokep b60fded
Merge remote-tracking branch 'origin/develop' into clokep/ignored-use…
clokep 30ce317
Add an intermediate method for threads.
clokep b0d4474
Do not cache on the ignored users parameter when fetching threads.
clokep 1b2c9a1
Add missing docstrings.
clokep 44f6975
Merge remote-tracking branch 'origin/develop' into clokep/ignored-use…
clokep 96d9215
Revert unused changes.
clokep e2910a4
Docstring.
clokep 7d6fa1e
Add logging.
clokep 61c7526
Merge remote-tracking branch 'origin/develop' into clokep/ignored-use…
clokep e95bd07
Merge remote-tracking branch 'origin/develop' into clokep/ignored-use…
clokep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix a long-standing bug where events from ignored users were still considered for relations. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix a long-standing bug where events from ignored users were still considered for relations. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix a long-standing bug where events from ignored users were still considered for relations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import logging | ||
from typing import TYPE_CHECKING, Dict, Iterable, Optional, cast | ||
from typing import TYPE_CHECKING, Dict, FrozenSet, Iterable, Optional, cast | ||
|
||
import attr | ||
from frozendict import frozendict | ||
|
@@ -21,6 +21,7 @@ | |
from synapse.api.errors import SynapseError | ||
from synapse.events import EventBase | ||
from synapse.types import JsonDict, Requester, StreamToken | ||
from synapse.visibility import filter_events_for_client | ||
|
||
if TYPE_CHECKING: | ||
from synapse.server import HomeServer | ||
|
@@ -62,6 +63,7 @@ def __bool__(self) -> bool: | |
class RelationsHandler: | ||
def __init__(self, hs: "HomeServer"): | ||
self._main_store = hs.get_datastores().main | ||
self._storage = hs.get_storage() | ||
self._auth = hs.get_auth() | ||
self._clock = hs.get_clock() | ||
self._event_handler = hs.get_event_handler() | ||
|
@@ -103,7 +105,8 @@ async def get_relations( | |
|
||
user_id = requester.user.to_string() | ||
|
||
await self._auth.check_user_in_room_or_world_readable( | ||
# TODO Properly handle a user leaving a room. | ||
(_, member_event_id) = await self._auth.check_user_in_room_or_world_readable( | ||
room_id, user_id, allow_departed_users=True | ||
) | ||
|
||
|
@@ -113,6 +116,9 @@ async def get_relations( | |
if event is None: | ||
raise SynapseError(404, "Unknown parent event.") | ||
|
||
# Note that ignored users are not passed into get_relations_for_event | ||
# below. Ignored users are handled in filter_events_for_client (and by | ||
# noy passing them in here we should get a better cache hit rate). | ||
pagination_chunk = await self._main_store.get_relations_for_event( | ||
event_id=event_id, | ||
event=event, | ||
|
@@ -130,6 +136,10 @@ async def get_relations( | |
[c["event_id"] for c in pagination_chunk.chunk] | ||
) | ||
|
||
events = await filter_events_for_client( | ||
self._storage, user_id, events, is_peeking=(member_event_id is None) | ||
) | ||
|
||
now = self._clock.time_msec() | ||
# Do not bundle aggregations when retrieving the original event because | ||
# we want the content before relations are applied to it. | ||
|
@@ -152,15 +162,15 @@ async def get_relations( | |
return return_value | ||
|
||
async def _get_bundled_aggregation_for_event( | ||
self, event: EventBase, user_id: str | ||
self, event: EventBase, ignored_users: FrozenSet[str] | ||
) -> Optional[BundledAggregations]: | ||
"""Generate bundled aggregations for an event. | ||
|
||
Note that this does not use a cache, but depends on cached methods. | ||
|
||
Args: | ||
event: The event to calculate bundled aggregations for. | ||
user_id: The user requesting the bundled aggregations. | ||
ignored_users: The users ignored by the requesting user. | ||
|
||
Returns: | ||
The bundled aggregations for an event, if bundled aggregations are | ||
|
@@ -184,15 +194,20 @@ async def _get_bundled_aggregation_for_event( | |
aggregations = BundledAggregations() | ||
|
||
annotations = await self._main_store.get_aggregation_groups_for_event( | ||
event_id, room_id | ||
event_id, room_id, ignored_users=ignored_users | ||
) | ||
if annotations.chunk: | ||
aggregations.annotations = await annotations.to_dict( | ||
cast("DataStore", self) | ||
) | ||
|
||
references = await self._main_store.get_relations_for_event( | ||
event_id, event, room_id, RelationTypes.REFERENCE, direction="f" | ||
event_id, | ||
event, | ||
room_id, | ||
RelationTypes.REFERENCE, | ||
direction="f", | ||
ignored_users=ignored_users, | ||
) | ||
if references.chunk: | ||
aggregations.references = await references.to_dict(cast("DataStore", self)) | ||
|
@@ -223,13 +238,21 @@ async def get_bundled_aggregations( | |
# event ID -> bundled aggregation in non-serialized form. | ||
results: Dict[str, BundledAggregations] = {} | ||
|
||
# Fetch any ignored users of the requesting user. | ||
ignored_users = await self._main_store.ignored_users(user_id) | ||
|
||
# Fetch other relations per event. | ||
for event in events_by_id.values(): | ||
event_result = await self._get_bundled_aggregation_for_event(event, user_id) | ||
event_result = await self._get_bundled_aggregation_for_event( | ||
event, ignored_users | ||
) | ||
if event_result: | ||
results[event.event_id] = event_result | ||
|
||
# Fetch any edits (but not for redacted events). | ||
# | ||
# Note that there is no use in limiting edits by ignored users since the | ||
# parent event should be ignored in the first place if the user is ignored. | ||
Comment on lines
+446
to
+447
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this sound like sound logic? I couldn't come up with a situation where we would need to check edits, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think it's probably fine. The only thing is if we decided in future to allow e.g. moderators to edit messages. |
||
edits = await self._main_store.get_applicable_edits( | ||
[ | ||
event_id | ||
|
@@ -241,7 +264,9 @@ async def get_bundled_aggregations( | |
results.setdefault(event_id, BundledAggregations()).replace = edit | ||
|
||
# Fetch thread summaries. | ||
summaries = await self._main_store.get_thread_summaries(events_by_id.keys()) | ||
summaries = await self._main_store.get_thread_summaries( | ||
events_by_id.keys(), ignored_users | ||
) | ||
# Only fetch participated for a limited selection based on what had | ||
# summaries. | ||
participated = await self._main_store.get_threads_participated( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this sound reasonable or do we think we should do the initial filtering by ignoring users too? (I think we would essentially do it twice then -- once in
get_relations_for_event
, and then again infilter_events_for_client
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense so long as we have this comment here.