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

Commit

Permalink
Avoid executing no-op queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Oct 31, 2023
1 parent 70b503f commit 3453eba
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions synapse/storage/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ def simple_insert_many_txn(
txn: LoggingTransaction,
table: str,
keys: Collection[str],
values: Iterable[Iterable[Any]],
values: Collection[Iterable[Any]],
) -> None:
"""Executes an INSERT query on the named table.
Expand All @@ -1145,6 +1145,9 @@ def simple_insert_many_txn(
keys: list of column names
values: for each row, a list of values in the same order as `keys`
"""
# IF there's nothing to insert, don't send the query.
if not values:
return

if isinstance(txn.database_engine, PostgresEngine):
# We use `execute_values` as it can be a lot faster than `execute_batch`,
Expand Down Expand Up @@ -1470,7 +1473,7 @@ def simple_upsert_many_txn(
key_names: Collection[str],
key_values: Collection[Iterable[Any]],
value_names: Collection[str],
value_values: Iterable[Iterable[Any]],
value_values: Collection[Iterable[Any]],
) -> None:
"""
Upsert, many times.
Expand All @@ -1483,6 +1486,9 @@ def simple_upsert_many_txn(
value_values: A list of each row's value column values.
Ignored if value_names is empty.
"""
if not value_values:
return

if table not in self._unsafe_to_upsert_tables:
return self.simple_upsert_many_txn_native_upsert(
txn, table, key_names, key_values, value_names, value_values
Expand Down Expand Up @@ -2059,6 +2065,8 @@ def simple_update_many_txn(
raise ValueError(
f"{len(key_values)} key rows and {len(value_values)} value rows: should be the same number."
)
if not value_values:
return

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

0 comments on commit 3453eba

Please sign in to comment.