diff options
author | Erik Johnston <erik@matrix.org> | 2023-05-03 14:41:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-03 13:41:37 +0000 |
commit | fc3a878220f934a248b008277e89b85ad187d220 (patch) | |
tree | 19835f32ff9977a68272f0e4b6012392899ba2fb /synapse/storage/database.py | |
parent | Suppress the trusted key server warning for matrix.org in the demo scripts (#... (diff) | |
download | synapse-fc3a878220f934a248b008277e89b85ad187d220.tar.xz |
Speed up rebuilding of the user directory for local users (#15529)
The idea here is to batch up the work.
Diffstat (limited to 'synapse/storage/database.py')
-rw-r--r-- | synapse/storage/database.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/synapse/storage/database.py b/synapse/storage/database.py index 1f5f5eb6f8..313cf1a8d0 100644 --- a/synapse/storage/database.py +++ b/synapse/storage/database.py @@ -386,13 +386,20 @@ class LoggingTransaction: self.executemany(sql, args) def execute_values( - self, sql: str, values: Iterable[Iterable[Any]], fetch: bool = True + self, + sql: str, + values: Iterable[Iterable[Any]], + template: Optional[str] = None, + fetch: bool = True, ) -> List[Tuple]: """Corresponds to psycopg2.extras.execute_values. Only available when using postgres. The `fetch` parameter must be set to False if the query does not return rows (e.g. INSERTs). + + The `template` is the snippet to merge to every item in argslist to + compose the query. """ assert isinstance(self.database_engine, PostgresEngine) from psycopg2.extras import execute_values @@ -400,7 +407,9 @@ class LoggingTransaction: return self._do_execute( # TODO: is it safe for values to be Iterable[Iterable[Any]] here? # https://www.psycopg.org/docs/extras.html?highlight=execute_batch#psycopg2.extras.execute_values says values should be Sequence[Sequence] - lambda the_sql: execute_values(self.txn, the_sql, values, fetch=fetch), + lambda the_sql: execute_values( + self.txn, the_sql, values, template=template, fetch=fetch + ), sql, ) |