diff options
-rw-r--r-- | synapse/storage/database.py | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/synapse/storage/database.py b/synapse/storage/database.py index 6e4cdfdd89..b394a6658b 100644 --- a/synapse/storage/database.py +++ b/synapse/storage/database.py @@ -2092,9 +2092,7 @@ class DatabasePool: Args: table: string giving the table name - keyvalues: dict of column names and values to select the row with. If an - empty dict is passed then no selection clauses are applied. Therefore, - ALL rows will be deleted. + keyvalues: dict of column names and values to select the row with desc: description of the transaction, for logging and metrics Returns: @@ -2114,17 +2112,15 @@ class DatabasePool: Args: table: string giving the table name - keyvalues: dict of column names and values to select the row with. If an - empty dict is passed then no selection clauses are applied. Therefore, - ALL rows will be deleted. + keyvalues: dict of column names and values to select the row with Returns: The number of deleted rows. """ - sql = "DELETE FROM %s" % (table,) - - if keyvalues: - sql += " WHERE %s" % (" AND ".join("%s = ?" % (k,) for k in keyvalues),) + sql = "DELETE FROM %s WHERE %s" % ( + table, + " AND ".join("%s = ?" % (k,) for k in keyvalues), + ) txn.execute(sql, list(keyvalues.values())) return txn.rowcount @@ -2139,19 +2135,18 @@ class DatabasePool: ) -> int: """Executes a DELETE query on the named table. - Filters rows if value of `column` is in `iterable`. + Filters rows by if value of `column` is in `iterable`. Args: table: string giving the table name column: column name to test for inclusion against `iterable` iterable: list of values to match against `column`. NB cannot be a generator as it may be evaluated multiple times. - keyvalues: dict of column names and values to select the rows with. If an - emtpy dict is passed, this option will have no effect. + keyvalues: dict of column names and values to select the rows with desc: description of the transaction, for logging and metrics Returns: - The number of deleted rows. + Number rows deleted """ return await self.runInteraction( desc, @@ -2183,11 +2178,10 @@ class DatabasePool: column: column name to test for inclusion against `values` values: values of `column` which choose rows to delete keyvalues: dict of extra column names and values to select the rows - with. They will be ANDed together with the main predicate. If an - empty dict is passed, this option will have no effect. + with. They will be ANDed together with the main predicate. Returns: - The number of deleted rows. + Number rows deleted """ if not values: return 0 @@ -2201,8 +2195,8 @@ class DatabasePool: clauses.append("%s = ?" % (key,)) values.append(value) - sql = "%s WHERE %s" % (sql, " AND ".join(clauses)) - + if clauses: + sql = "%s WHERE %s" % (sql, " AND ".join(clauses)) txn.execute(sql, values) return txn.rowcount |