This repository was 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
fix bug #2969 (loading all state for a given type from the DB if the state_key is None) #2990
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 |
|---|---|---|
|
|
@@ -240,6 +240,9 @@ def _get_state_groups_from_groups_txn(self, txn, groups, types=None): | |
| ( | ||
| "AND type = ? AND state_key = ?", | ||
| (etype, state_key) | ||
| ) if state_key is not None else ( | ||
| "AND type = ?", | ||
| (etype,) | ||
| ) | ||
| for etype, state_key in types | ||
| ] | ||
|
|
@@ -259,10 +262,19 @@ def _get_state_groups_from_groups_txn(self, txn, groups, types=None): | |
| key = (typ, state_key) | ||
| results[group][key] = event_id | ||
| else: | ||
| where_args = [] | ||
| where_clauses = [] | ||
| wildcard_types = False | ||
| if types is not None: | ||
| where_clause = "AND (%s)" % ( | ||
| " OR ".join(["(type = ? AND state_key = ?)"] * len(types)), | ||
| ) | ||
| for typ in types: | ||
| if typ[1] is None: | ||
| where_clauses.append("(type = ?)") | ||
| where_args.extend(typ[0]) | ||
| wildcard_types = True | ||
| else: | ||
| where_clauses.append("(type = ? AND state_key = ?)") | ||
| where_args.extend([typ[0], typ[1]]) | ||
| where_clause = "AND (%s)" % (" OR ".join(where_clauses)) | ||
| else: | ||
| where_clause = "" | ||
|
|
||
|
|
@@ -279,7 +291,7 @@ def _get_state_groups_from_groups_txn(self, txn, groups, types=None): | |
| # after we finish deduping state, which requires this func) | ||
| args = [next_group] | ||
| if types: | ||
|
Member
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. this can be unconditional now:
Member
Author
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, although unclear what that buys us? (plus in my lazyloading PR we do have other if's at that point)
Member
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. simplicity, mostly. but I agree it's not a big deal. |
||
| args.extend(i for typ in types for i in typ) | ||
| args.extend(where_args) | ||
|
|
||
| txn.execute( | ||
| "SELECT type, state_key, event_id FROM state_groups_state" | ||
|
|
@@ -292,9 +304,17 @@ def _get_state_groups_from_groups_txn(self, txn, groups, types=None): | |
| if (typ, state_key) not in results[group] | ||
| ) | ||
|
|
||
| # If the lengths match then we must have all the types, | ||
| # so no need to go walk further down the tree. | ||
| if types is not None and len(results[group]) == len(types): | ||
| # If the number of entries in the (type,state_key)->event_id dict | ||
| # matches the number of (type,state_keys) types we were searching | ||
| # for, then we must have found them all, so no need to go walk | ||
| # further down the tree... UNLESS our types filter contained | ||
| # wildcards (i.e. Nones) in which case we have to do an exhaustive | ||
| # search | ||
| if ( | ||
| types is not None and | ||
| not wildcard_types and | ||
| len(results[group]) == len(types) | ||
| ): | ||
| break | ||
|
|
||
| next_group = self._simple_select_one_onecol_txn( | ||
|
|
||
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.
it'd be nice to define this inside the
ifclause where it is usedThere 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 may be going insane, but i'm failing to see why? it's used outside the if clause, so isn't it nicer to define it at the 'right' scope level, rather than give the impression that it's scoped to the if block (even though python scoping extends to the whole def?)
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 may be going insane, but I can't see it being used outside the
ifclause?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.
surely where_args & where_clauses are used much later on to actually execute the query. hence defining them at the scope common to both. or are we talking about different if clauses?
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'm talking about
where_clauses, which is used at lines 270, 273 and 275. They are all inside the next if clause.synapse/synapse/storage/state.py
Lines 267 to 275 in b2aba9e