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
Improvements to bundling aggregations #11815
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
de8a4bc
Do not mutate result dictionaries.
clokep 42e1817
Fetch all bundled aggregations at once.
clokep 12e8832
Create a BundledAggregations attrs.
clokep 9f3d783
Newsfragment
clokep 0d3b625
Merge remote-tracking branch 'origin/develop' into clokep/bundled-agg…
clokep 1777831
Convert retun type of get_events_around to attrs.
clokep 4a91ae8
Merge remote-tracking branch 'origin/develop' into clokep/bundled-agg…
clokep 067d4bc
Add missing assert in tests.
clokep d976be7
Do not include empty bundled aggregations.
clokep 5d635bf
Merge remote-tracking branch 'origin/develop' into clokep/bundled-agg…
clokep ca89fb6
Merge remote-tracking branch 'origin/develop' into clokep/bundled-agg…
clokep 10cb9d5
Merge remote-tracking branch 'origin/develop' into clokep/bundled-agg…
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 @@ | ||
Improve type safety of bundled aggregations code. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -361,36 +361,37 @@ async def search( | |
|
||
logger.info( | ||
"Context for search returned %d and %d events", | ||
len(res["events_before"]), | ||
len(res["events_after"]), | ||
len(res.events_before), | ||
len(res.events_after), | ||
) | ||
|
||
res["events_before"] = await filter_events_for_client( | ||
self.storage, user.to_string(), res["events_before"] | ||
events_before = await filter_events_for_client( | ||
self.storage, user.to_string(), res.events_before | ||
) | ||
|
||
res["events_after"] = await filter_events_for_client( | ||
self.storage, user.to_string(), res["events_after"] | ||
events_after = await filter_events_for_client( | ||
self.storage, user.to_string(), res.events_after | ||
) | ||
|
||
res["start"] = await now_token.copy_and_replace( | ||
"room_key", res["start"] | ||
).to_string(self.store) | ||
|
||
res["end"] = await now_token.copy_and_replace( | ||
"room_key", res["end"] | ||
).to_string(self.store) | ||
context = { | ||
"events_before": events_before, | ||
"events_after": events_after, | ||
"start": await now_token.copy_and_replace( | ||
"room_key", res.start | ||
).to_string(self.store), | ||
"end": await now_token.copy_and_replace( | ||
"room_key", res.end | ||
).to_string(self.store), | ||
} | ||
|
||
if include_profile: | ||
senders = { | ||
ev.sender | ||
for ev in itertools.chain( | ||
res["events_before"], [event], res["events_after"] | ||
) | ||
for ev in itertools.chain(events_before, [event], events_after) | ||
} | ||
|
||
if res["events_after"]: | ||
last_event_id = res["events_after"][-1].event_id | ||
if events_after: | ||
last_event_id = events_after[-1].event_id | ||
else: | ||
last_event_id = event.event_id | ||
|
||
|
@@ -402,7 +403,7 @@ async def search( | |
last_event_id, state_filter | ||
) | ||
|
||
res["profile_info"] = { | ||
context["profile_info"] = { | ||
s.state_key: { | ||
"displayname": s.content.get("displayname", None), | ||
"avatar_url": s.content.get("avatar_url", None), | ||
|
@@ -411,7 +412,7 @@ async def search( | |
if s.type == EventTypes.Member and s.state_key in senders | ||
} | ||
|
||
contexts[event.event_id] = res | ||
contexts[event.event_id] = context | ||
else: | ||
contexts = {} | ||
|
||
|
@@ -421,10 +422,10 @@ async def search( | |
|
||
for context in contexts.values(): | ||
context["events_before"] = self._event_serializer.serialize_events( | ||
context["events_before"], time_now | ||
context["events_before"], time_now # type: ignore[arg-type] | ||
) | ||
context["events_after"] = self._event_serializer.serialize_events( | ||
context["events_after"], time_now | ||
context["events_after"], time_now # type: ignore[arg-type] | ||
) | ||
Comment on lines
423
to
429
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. Yes, this still mutates the dictionary, but it seems rather messy to not do this... |
||
|
||
state_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
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.
I think we're still doing some mutation of
results
on lines +1184 to +1190 above. Not sure if that's intentional? It seems to conflict with the title of this commit!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, we are...I initially had converted that too and then stopped. I think it got messy, let me give it a try again 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've updated this to not mutate those results, it got a bit messy though. Let me know if you'd prefer I back it out. See 1777831.
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.
To be honest I don't mind too much either way. (I was mostly checking that we hadn't missed a bit of work that we'd intended to do, judging by the commit message).
I like that the change makes it a bit easier to see what you get out of
get_events_around
(i.e. a thing with specific fields rather than an arbitrary dictionary), but I don't really have a strong opinion here. Happy to defer to your judgement!