diff options
author | Andrew Morgan <andrewm@element.io> | 2022-08-04 16:37:10 +0100 |
---|---|---|
committer | Andrew Morgan <andrewm@element.io> | 2022-08-04 16:37:10 +0100 |
commit | efc492ed99438d21dc1163adcd4bd0c105eb3bf5 (patch) | |
tree | 878ddac16e745ca0e56413ce5b48fbdb62d4bd49 | |
parent | update the changelog entries (diff) | |
download | synapse-efc492ed99438d21dc1163adcd4bd0c105eb3bf5.tar.xz |
Do not return the number of deleted rows from simple_truncate
Postgres does not support returning this information for a TRUNCATE command.
-rw-r--r-- | synapse/storage/database.py | 19 | ||||
-rw-r--r-- | tests/storage/test__base.py | 4 |
2 files changed, 8 insertions, 15 deletions
diff --git a/synapse/storage/database.py b/synapse/storage/database.py index 396d09ac4f..9cce458dfc 100644 --- a/synapse/storage/database.py +++ b/synapse/storage/database.py @@ -2204,20 +2204,18 @@ class DatabasePool: return txn.rowcount - async def simple_truncate(self, table: str, desc: str) -> int: + async def simple_truncate(self, table: str, desc: str) -> None: """Executes a TRUNCATE query on the given table, deleting all rows. SQLite does not support TRUNCATE, thus a 'DELETE FROM table_name' will - be used instead. + be used instead. This method does not return the number of rows deleted, + as this is not returned by postgres for TRUNCATE commands. Args: table: The name of the table to delete all rows from. desc: description of the transaction, for logging and metrics. - - Returns: - The number of deleted rows. """ - return await self.runInteraction( + await self.runInteraction( desc, self._simple_truncate_txn, table, db_autocommit=True ) @@ -2225,18 +2223,16 @@ class DatabasePool: def _simple_truncate_txn( txn: LoggingTransaction, table: str, - ) -> int: + ) -> None: """Executes a TRUNCATE query on the given table, deleting all rows. SQLite does not support TRUNCATE, thus a 'DELETE FROM table_name' will - be used instead. + be used instead. This method does not return the number of rows deleted, + as this is not returned by postgres for TRUNCATE commands. Args: txn: Transaction object table: The name of the table to delete all rows from. - - Returns: - The number of deleted rows. """ if isinstance(txn.database_engine, PostgresEngine): sql = "TRUNCATE %s" % table @@ -2245,7 +2241,6 @@ class DatabasePool: sql = "DELETE FROM %s" % table txn.execute(sql) - return txn.rowcount def get_cache_dict( self, diff --git a/tests/storage/test__base.py b/tests/storage/test__base.py index 50399b90f3..de1c145e54 100644 --- a/tests/storage/test__base.py +++ b/tests/storage/test__base.py @@ -196,14 +196,12 @@ class SimpleTruncateTestCase(unittest.HomeserverTestCase): self.assertGreater(len(table_rows), 0) # Attempt to truncate the table - number_of_deleted_rows = self.get_success( + self.get_success( self.storage.db_pool.simple_truncate( table=self.table_name, desc="simple_truncate_test_truncate", ) ) - # Check that the number of deleted rows is as we expect. - self.assertEqual(number_of_deleted_rows, len(table_rows)) # Perform another select and ensure there are no remaining rows. table_rows = self.get_success( |