Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 3453eba

Browse files
committed
Avoid executing no-op queries.
1 parent 70b503f commit 3453eba

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

synapse/storage/database.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ def simple_insert_many_txn(
11321132
txn: LoggingTransaction,
11331133
table: str,
11341134
keys: Collection[str],
1135-
values: Iterable[Iterable[Any]],
1135+
values: Collection[Iterable[Any]],
11361136
) -> None:
11371137
"""Executes an INSERT query on the named table.
11381138
@@ -1145,6 +1145,9 @@ def simple_insert_many_txn(
11451145
keys: list of column names
11461146
values: for each row, a list of values in the same order as `keys`
11471147
"""
1148+
# IF there's nothing to insert, don't send the query.
1149+
if not values:
1150+
return
11481151

11491152
if isinstance(txn.database_engine, PostgresEngine):
11501153
# We use `execute_values` as it can be a lot faster than `execute_batch`,
@@ -1470,7 +1473,7 @@ def simple_upsert_many_txn(
14701473
key_names: Collection[str],
14711474
key_values: Collection[Iterable[Any]],
14721475
value_names: Collection[str],
1473-
value_values: Iterable[Iterable[Any]],
1476+
value_values: Collection[Iterable[Any]],
14741477
) -> None:
14751478
"""
14761479
Upsert, many times.
@@ -1483,6 +1486,9 @@ def simple_upsert_many_txn(
14831486
value_values: A list of each row's value column values.
14841487
Ignored if value_names is empty.
14851488
"""
1489+
if not value_values:
1490+
return
1491+
14861492
if table not in self._unsafe_to_upsert_tables:
14871493
return self.simple_upsert_many_txn_native_upsert(
14881494
txn, table, key_names, key_values, value_names, value_values
@@ -2059,6 +2065,8 @@ def simple_update_many_txn(
20592065
raise ValueError(
20602066
f"{len(key_values)} key rows and {len(value_values)} value rows: should be the same number."
20612067
)
2068+
if not value_values:
2069+
return
20622070

20632071
# List of tuples of (value values, then key values)
20642072
# (This matches the order needed for the query)

0 commit comments

Comments
 (0)