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
Experimental support to include bundled aggregations in search results (MSC3666) #11837
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bbd10e3
Remove an unused variable.
clokep 4b3aebe
Include aggregations in results.
clokep 1de1e58
Newsfragment
clokep 3bd4e78
Merge remote-tracking branch 'origin/develop' into clokep/search-aggr…
clokep adfdc64
Only request bundled aggregations for a single event once.
clokep 58ebd31
Merge remote-tracking branch 'origin/develop' into clokep/search-aggr…
clokep 3c2336b
Fix some inefficiencies due to a merge.
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 @@ | ||
Experimental support for [MSC3666](https://github.com/matrix-org/matrix-doc/pull/3666): including bundled aggregations in server side search results. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,8 @@ def __init__(self, hs: "HomeServer"): | |
self.state_store = self.storage.state | ||
self.auth = hs.get_auth() | ||
|
||
self._msc3666_enabled = hs.config.experimental.msc3666_enabled | ||
|
||
async def get_old_rooms_from_upgraded_room(self, room_id: str) -> Iterable[str]: | ||
"""Retrieves room IDs of old rooms in the history of an upgraded room. | ||
|
||
|
@@ -238,8 +240,6 @@ async def search( | |
|
||
results = search_result["results"] | ||
|
||
results_map = {r["event"].event_id: r for r in results} | ||
|
||
rank_map.update({r["event"].event_id: r["rank"] for r in results}) | ||
|
||
filtered_events = await search_filter.filter([r["event"] for r in results]) | ||
|
@@ -420,12 +420,29 @@ async def search( | |
|
||
time_now = self.clock.time_msec() | ||
|
||
aggregations = None | ||
if self._msc3666_enabled: | ||
aggregations = await self.store.get_bundled_aggregations( | ||
# Generate an iterable of EventBase for all the events that will be | ||
# returned, including contextual events. | ||
itertools.chain( | ||
# The events_before and events_after for each context. | ||
itertools.chain.from_iterable( | ||
itertools.chain(context["events_before"], context["events_after"]) # type: ignore[arg-type] | ||
for context in contexts.values() | ||
), | ||
# The returned events. | ||
allowed_events, | ||
), | ||
Comment on lines
+426
to
+436
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. hrm. I think it's quite likely that we'll end up with some duplicates in here. Maybe we could have 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. Hmm, the results are cached so hopefully we would just immediately hit the cache, but depending on that seems not very nice. Good call! 👍 |
||
user.to_string(), | ||
) | ||
|
||
for context in contexts.values(): | ||
context["events_before"] = self._event_serializer.serialize_events( | ||
context["events_before"], time_now # type: ignore[arg-type] | ||
context["events_before"], time_now, bundle_aggregations=aggregations # type: ignore[arg-type] | ||
) | ||
context["events_after"] = self._event_serializer.serialize_events( | ||
context["events_after"], time_now # type: ignore[arg-type] | ||
context["events_after"], time_now, bundle_aggregations=aggregations # type: ignore[arg-type] | ||
) | ||
|
||
state_results = {} | ||
|
@@ -442,7 +459,9 @@ async def search( | |
results.append( | ||
{ | ||
"rank": rank_map[e.event_id], | ||
"result": self._event_serializer.serialize_event(e, time_now), | ||
"result": self._event_serializer.serialize_event( | ||
e, time_now, bundle_aggregations=aggregations | ||
), | ||
"context": contexts.get(e.event_id, {}), | ||
} | ||
) | ||
|
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
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.
ugh. If this function wasn't 50000 lines long, we'd be able to follow this sort of thing much more easily.
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.
Yeah, PyCharm noticed it and declared it unused. 😢
I can refactor this method a bit first if you'd like. I think moving the
context
calculation would be easy enough.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.
it would certainly be nice to refactor it if you have a few tuits. Suggest doing as a followup though.
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.
I took a look at doing this and it quickly spiraled. Will do as a follow-up.