Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ecb20a4
Add psycopg package.
clokep Nov 9, 2023
c7e3120
Method to set statement timeout.
clokep Nov 15, 2023
91ef287
Separate PostgresEngine into Psycopg2Engine and PsycopgEngine.
clokep Nov 9, 2023
0a06be1
Run tests in CI against psycopg.
clokep Nov 9, 2023
260a5b7
Update user directory to handle psycopg3.
clokep Oct 9, 2024
ce8ad96
Support execute_values on psycopg3.
clokep Oct 9, 2024
93b1740
Fix-up simple_* tests.
clokep Oct 10, 2024
d49827d
Fix-up calls to end_to_end_keys.
clokep Oct 10, 2024
287f0a6
Use superclass version of `executescript()` (#1)
realtyem Oct 17, 2024
9f77ac4
Switch out formatting placeholder for what psycopg2 is expecting (#2)
realtyem Oct 17, 2024
3bbd562
Merge remote-tracking branch 'upstream/develop' into psycopg3
clokep Oct 23, 2024
f5b6429
Linting (and a fix) (#3)
realtyem Oct 23, 2024
7ff4584
Merge remote-tracking branch 'refs/remotes/origin/psycopg3' into psyc…
clokep Oct 23, 2024
5353f8d
Try running complement builds?
clokep Oct 24, 2024
1bec3d7
Merge branch 'develop' into psycopg3
realtyem Jul 21, 2025
f6c2364
Adjust type: ignore line to where mypy will apply it
realtyem Jul 21, 2025
279791d
Add both PsycopgEngine and Psycopg2Engine to database.engines.__all__…
realtyem Jul 21, 2025
1ceb332
Adjust _mark_state_groups_as_pending_deletion_txn() to use execute_ba…
realtyem Jul 21, 2025
95eb7f8
Adjust set_profile_field() insertion sql for a narrower type on param…
realtyem Jul 22, 2025
4ad733f
Try an update to the config schema?
realtyem Jul 22, 2025
f65a885
Adjust unit tests to reflect updated minimal versions of python/postgres
realtyem Jul 22, 2025
425971f
Minor changes to profile field
clokep Sep 30, 2025
61a3aaa
Merge remote-tracking branch 'upstream/develop' into psycopg3
clokep Sep 30, 2025
f31d8d2
Newsfragment
clokep Sep 30, 2025
ad229a9
Merge remote-tracking branch 'upstream/develop' into psycopg3
clokep Sep 30, 2025
2f4352b
poetry lock again
clokep Sep 30, 2025
467a8c4
Merge branch 'develop' into psycopg3
clokep Oct 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions synapse/storage/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def execute_batch(self, sql: str, args: Iterable[Iterable[Any]]) -> None:
def execute_values(
self,
sql: str,
values: Iterable[Iterable[Any]],
values: Collection[Iterable[Any]],
template: Optional[str] = None,
fetch: bool = True,
) -> List[Tuple]:
Expand All @@ -420,6 +420,10 @@ def execute_values(
"""
assert isinstance(self.database_engine, PostgresEngine)

# If there's no work to do, skip.
if not len(values):
return []

if isinstance(self.database_engine, Psycopg2Engine):
from psycopg2.extras import execute_values

Expand Down Expand Up @@ -2431,7 +2435,7 @@ def simple_delete_many_batch_txn(
values: for each row, a list of values in the same order as `keys`
"""

if isinstance(txn.database_engine, PostgresEngine):
if isinstance(txn.database_engine, Psycopg2Engine):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we open a ticket about this as well. A solution might be to pass in an array and rely on UNNEST, but that is something I'm more than happy to defer to later, it just would be nice to remember to do it

# We use `execute_values` as it can be a lot faster than `execute_batch`,
# but it's only available on postgres.
sql = "DELETE FROM %s WHERE (%s) IN (VALUES ?)" % (
Expand Down
8 changes: 4 additions & 4 deletions synapse/storage/databases/main/end_to_end_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
make_tuple_in_list_sql_clause,
)
from synapse.storage.databases.main.cache import CacheInvalidationWorkerStore
from synapse.storage.engines import PostgresEngine
from synapse.storage.engines import PostgresEngine, Psycopg2Engine
from synapse.storage.util.id_generators import MultiWriterIdGenerator
from synapse.types import JsonDict, JsonMapping
from synapse.util import json_decoder, json_encoder
Expand Down Expand Up @@ -1134,7 +1134,7 @@ async def claim_e2e_one_time_keys(
"""
results: Dict[str, Dict[str, Dict[str, JsonDict]]] = {}
missing: List[Tuple[str, str, str, int]] = []
if isinstance(self.database_engine, PostgresEngine):
if isinstance(self.database_engine, Psycopg2Engine):
# If we can use execute_values we can use a single batch query
# in autocommit mode.
unfulfilled_claim_counts: Dict[Tuple[str, str, str], int] = {}
Expand Down Expand Up @@ -1197,7 +1197,7 @@ async def claim_e2e_fallback_keys(
Returns:
A map of user ID -> a map device ID -> a map of key ID -> JSON.
"""
if isinstance(self.database_engine, PostgresEngine):
if isinstance(self.database_engine, Psycopg2Engine):
return await self.db_pool.runInteraction(
"_claim_e2e_fallback_keys_bulk",
self._claim_e2e_fallback_keys_bulk_txn,
Expand Down Expand Up @@ -1230,7 +1230,7 @@ def _claim_e2e_fallback_keys_bulk_txn(
SET used = used OR mark_as_used
FROM claims
WHERE (k.user_id, k.device_id, k.algorithm) = (claims.user_id, claims.device_id, claims.algorithm)
RETURNING k.user_id, k.device_id, k.algorithm, k.key_id, k.key_json;
RETURNING k.user_id, k.device_id, k.algorithm, k.key_id, k.key_json
"""
claimed_keys = cast(
List[Tuple[str, str, str, str, str]],
Expand Down