-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
More precise type for LoggingTransaction.execute #15432
Changes from 7 commits
444b231
75a70af
f0863f7
b1f8cb6
c83dbb2
56a9f75
162d851
2672b7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Improve type hints. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,10 @@ def __init__(self, room_id: str): | |
|
||
|
||
class EventFederationWorkerStore(SignatureWorkerStore, EventsWorkerStore, SQLBaseStore): | ||
# TODO: this attribute comes from EventPushActionWorkerStore. Should we inherit from | ||
# that store so that mypy can deduce this for itself? | ||
stream_ordering_month_ago: Optional[int] | ||
Comment on lines
+117
to
+119
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. I can't see why this should live on EventPushActionsWorkerStore (and I can't see anywhere else that uses it). I think it'd make more sense to move this onto EventsWorkerStore if we anticipate other users, and here if not. 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.
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 change seems unrelated, did the above changes shake it out somehow?) 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. If I don't make this change then mypy doesn't know what 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.
I might have overly aggressively resolved this -- did we want to do this? 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. I wasn't in any particular hurry tbh! |
||
|
||
def __init__( | ||
self, | ||
database: DatabasePool, | ||
|
@@ -1182,8 +1186,8 @@ async def have_room_forward_extremities_changed_since( | |
Throws a StoreError if we have since purged the index for | ||
stream_orderings from that point. | ||
""" | ||
|
||
if stream_ordering <= self.stream_ordering_month_ago: # type: ignore[attr-defined] | ||
assert self.stream_ordering_month_ago is not None | ||
if stream_ordering <= self.stream_ordering_month_ago: | ||
raise StoreError(400, f"stream_ordering too old {stream_ordering}") | ||
|
||
sql = """ | ||
|
@@ -1231,7 +1235,8 @@ async def get_forward_extremities_for_room_at_stream_ordering( | |
|
||
# provided the last_change is recent enough, we now clamp the requested | ||
# stream_ordering to it. | ||
if last_change > self.stream_ordering_month_ago: # type: ignore[attr-defined] | ||
assert self.stream_ordering_month_ago is not None | ||
if last_change > self.stream_ordering_month_ago: | ||
stream_ordering = min(last_change, stream_ordering) | ||
|
||
return await self._get_forward_extremeties_for_room(room_id, stream_ordering) | ||
|
@@ -1246,8 +1251,8 @@ async def _get_forward_extremeties_for_room( | |
Throws a StoreError if we have since purged the index for | ||
stream_orderings from that point. | ||
""" | ||
|
||
if stream_ordering <= self.stream_ordering_month_ago: # type: ignore[attr-defined] | ||
assert self.stream_ordering_month_ago is not None | ||
if stream_ordering <= self.stream_ordering_month_ago: | ||
raise StoreError(400, "stream_ordering too old %s" % (stream_ordering,)) | ||
|
||
sql = """ | ||
|
@@ -1707,9 +1712,7 @@ def _delete_old_forward_extrem_cache_txn(txn: LoggingTransaction) -> None: | |
DELETE FROM stream_ordering_to_exterm | ||
WHERE stream_ordering < ? | ||
""" | ||
txn.execute( | ||
sql, (self.stream_ordering_month_ago,) # type: ignore[attr-defined] | ||
) | ||
txn.execute(sql, (self.stream_ordering_month_ago,)) | ||
|
||
await self.db_pool.runInteraction( | ||
"_delete_old_forward_extrem_cache", | ||
|
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.
If we're now importing
_Parameters
somewhere else can we rename it toTransactionParameters
or something? It could also use a comment above it...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.
Can do. Will probably call it
ExecuteParameters
orQueryParameters
.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.
Went for
SQLQueryParamters
in the end (as opposed to URL query parameters).