diff options
author | Patrick Cloke <patrickc@matrix.org> | 2023-11-15 13:38:57 -0500 |
---|---|---|
committer | Patrick Cloke <patrickc@matrix.org> | 2023-11-15 14:29:22 -0500 |
commit | 17ba1a9c1e353f85e464d584a036558997fe1f34 (patch) | |
tree | 67aec6e180a7df48f4750999efed3ecf4292ba54 /synapse/storage/engines/postgres.py | |
parent | Run tests in CI against psycopg. (diff) | |
download | synapse-github/clokep/psycopg3-driver.tar.xz |
Method to set statement timeout. github/clokep/psycopg3-driver clokep/psycopg3-driver
Diffstat (limited to 'synapse/storage/engines/postgres.py')
-rw-r--r-- | synapse/storage/engines/postgres.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/synapse/storage/engines/postgres.py b/synapse/storage/engines/postgres.py index 911abddc19..05a5330ed7 100644 --- a/synapse/storage/engines/postgres.py +++ b/synapse/storage/engines/postgres.py @@ -64,6 +64,11 @@ class PostgresEngine( """ ... + @abc.abstractmethod + def set_statement_timeout(self, cursor: CursorType, statement_timeout: int) -> None: + """Configure the current cursor's statement timeout.""" + ... + @property def single_threaded(self) -> bool: return False @@ -168,15 +173,7 @@ class PostgresEngine( # Abort really long-running statements and turn them into errors. if self.statement_timeout is not None: - # TODO Avoid a circular import, this needs to be abstracted. - if self.__class__.__name__ == "Psycopg2Engine": - cursor.execute("SET statement_timeout TO ?", (self.statement_timeout,)) - else: - cursor.execute( - sql.SQL("SET statement_timeout TO {}").format( - self.statement_timeout - ) - ) + self.set_statement_timeout(cursor.txn, self.statement_timeout) # type: ignore[arg-type] cursor.close() db_conn.commit() |