Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Improve comments in StateGroupBackgroundUpdateStore. #16383

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/16383.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve comments in `StateGroupBackgroundUpdateStore`.
18 changes: 16 additions & 2 deletions synapse/storage/databases/state/bg_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ def _get_state_groups_from_groups_txn(
groups: List[int],
state_filter: Optional[StateFilter] = None,
) -> Mapping[int, StateMap[str]]:
"""
Given a number of state groups, fetch the latest state for each group.

Args:
txn: The transaction object.
groups: The given state groups that you want to fetch the latest state for.
state_filter: The state filter to apply the state we fetch state from the database.

Returns:
Map from state_group to a StateMap at that point.
"""

state_filter = state_filter or StateFilter.all()

results: Dict[int, MutableStateMap[str]] = {group: {} for group in groups}
Expand Down Expand Up @@ -206,8 +218,10 @@ def _get_state_groups_from_groups_txn(
if where_clause:
where_clause = " AND (%s)" % (where_clause,)

# We don't use WITH RECURSIVE on sqlite3 as there are distributions
# that ship with an sqlite3 version that doesn't support it (e.g. wheezy)
# XXX: We could `WITH RECURSIVE` here since it's supported on SQLite 3.8.3
# or higher and our minimum supported version is greater than that.
#
# We just haven't put in the time to refactor this.
Comment on lines +221 to +224
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would love to see this (because I hate having to write SQL twice!)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or indeed read)

for group in groups:
next_group: Optional[int] = group

Expand Down
Loading