mirror of
https://github.com/element-hq/synapse
synced 2024-06-30 18:23:28 +00:00
Do not return the number of deleted rows from simple_truncate
Postgres does not support returning this information for a TRUNCATE command.
This commit is contained in:
parent
1da8f115b5
commit
efc492ed99
|
@ -2204,20 +2204,18 @@ class DatabasePool:
|
||||||
|
|
||||||
return txn.rowcount
|
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.
|
"""Executes a TRUNCATE query on the given table, deleting all rows.
|
||||||
|
|
||||||
SQLite does not support TRUNCATE, thus a 'DELETE FROM table_name' will
|
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:
|
Args:
|
||||||
table: The name of the table to delete all rows from.
|
table: The name of the table to delete all rows from.
|
||||||
desc: description of the transaction, for logging and metrics.
|
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
|
desc, self._simple_truncate_txn, table, db_autocommit=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2225,18 +2223,16 @@ class DatabasePool:
|
||||||
def _simple_truncate_txn(
|
def _simple_truncate_txn(
|
||||||
txn: LoggingTransaction,
|
txn: LoggingTransaction,
|
||||||
table: str,
|
table: str,
|
||||||
) -> int:
|
) -> None:
|
||||||
"""Executes a TRUNCATE query on the given table, deleting all rows.
|
"""Executes a TRUNCATE query on the given table, deleting all rows.
|
||||||
|
|
||||||
SQLite does not support TRUNCATE, thus a 'DELETE FROM table_name' will
|
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:
|
Args:
|
||||||
txn: Transaction object
|
txn: Transaction object
|
||||||
table: The name of the table to delete all rows from.
|
table: The name of the table to delete all rows from.
|
||||||
|
|
||||||
Returns:
|
|
||||||
The number of deleted rows.
|
|
||||||
"""
|
"""
|
||||||
if isinstance(txn.database_engine, PostgresEngine):
|
if isinstance(txn.database_engine, PostgresEngine):
|
||||||
sql = "TRUNCATE %s" % table
|
sql = "TRUNCATE %s" % table
|
||||||
|
@ -2245,7 +2241,6 @@ class DatabasePool:
|
||||||
sql = "DELETE FROM %s" % table
|
sql = "DELETE FROM %s" % table
|
||||||
|
|
||||||
txn.execute(sql)
|
txn.execute(sql)
|
||||||
return txn.rowcount
|
|
||||||
|
|
||||||
def get_cache_dict(
|
def get_cache_dict(
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -196,14 +196,12 @@ class SimpleTruncateTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertGreater(len(table_rows), 0)
|
self.assertGreater(len(table_rows), 0)
|
||||||
|
|
||||||
# Attempt to truncate the table
|
# Attempt to truncate the table
|
||||||
number_of_deleted_rows = self.get_success(
|
self.get_success(
|
||||||
self.storage.db_pool.simple_truncate(
|
self.storage.db_pool.simple_truncate(
|
||||||
table=self.table_name,
|
table=self.table_name,
|
||||||
desc="simple_truncate_test_truncate",
|
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.
|
# Perform another select and ensure there are no remaining rows.
|
||||||
table_rows = self.get_success(
|
table_rows = self.get_success(
|
||||||
|
|
Loading…
Reference in a new issue