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

Add comma missing from #15382. #15429

Merged
merged 2 commits into from
Apr 13, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/15429.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve DB performance of clearing out old data from `stream_ordering_to_exterm`.
2 changes: 1 addition & 1 deletion synapse/storage/databases/main/event_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,7 @@ def _delete_old_forward_extrem_cache_txn(txn: LoggingTransaction) -> None:
WHERE stream_ordering < ?
"""
txn.execute(
sql, (self.stream_ordering_month_ago) # type: ignore[attr-defined]
sql, (self.stream_ordering_month_ago,) # type: ignore[attr-defined]
Copy link
Contributor

Choose a reason for hiding this comment

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

Anyway for the linting to catch this?

Copy link
Contributor

Choose a reason for hiding this comment

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

def execute(self, sql: str, *args: Any) -> None:
self._do_execute(self.txn.execute, sql, *args)
could require that args: Tuple[Any] maybe?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, that's actually already the case. If *args: T then args: Tuple[T]. So here args: Tuple[Any].

Tracing it through: _do_execute_ is annotated to require that self.txn.execute(sql, *args) is type-safe.

def _do_execute(
self,
func: Callable[Concatenate[str, P], R],
sql: str,
*args: P.args,
**kwargs: P.kwargs,
) -> R:

self.txn is a Cursor and Cursor.execute is annotated as

_Parameters = Union[Sequence[Any], Mapping[str, Any]]
class Cursor(Protocol):
def execute(self, sql: str, parameters: _Parameters = ...) -> Any:
...

So for self.txn.execute(sql, *args) to be type-correct, we need *args to contain exactly one argument arg[0] which is a _Parameters instance. In this situation arg[0] : Any so this trivially passes.

I think the signature for execute is wrong. I think it should match that of self.txn.execute and take a _Parameters.

Well, consider me sniped. I'm going to see if I can PR this.

Copy link
Contributor

Choose a reason for hiding this comment

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

-> #15432

)

await self.db_pool.runInteraction(
Expand Down