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

Commit 8650283

Browse files
committed
Add some clarifications to README.md in the database schema directory. (#6615)
* commit '4fb5f4d0c': Add some clarifications to README.md in the database schema directory. (#6615) Minor perf fixes to `get_auth_chain_ids`.
2 parents 2c6aae8 + 4fb5f4d commit 8650283

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

changelog.d/6615.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add some clarifications to `README.md` in the database schema directory.

changelog.d/6954.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Minor perf fixes to `get_auth_chain_ids`.

synapse/storage/data_stores/main/event_federation.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import logging
1717
from typing import List, Optional, Set
1818

19-
from six.moves import range
2019
from six.moves.queue import Empty, PriorityQueue
2120

2221
from twisted.internet import defer
@@ -28,6 +27,7 @@
2827
from synapse.storage.data_stores.main.signatures import SignatureWorkerStore
2928
from synapse.storage.database import Database
3029
from synapse.util.caches.descriptors import cached
30+
from synapse.util.iterutils import batch_iter
3131

3232
logger = logging.getLogger(__name__)
3333

@@ -88,14 +88,12 @@ def _get_auth_chain_ids_txn(self, txn, event_ids, include_given, ignore_events):
8888
front = set(event_ids)
8989
while front:
9090
new_front = set()
91-
front_list = list(front)
92-
chunks = [front_list[x : x + 100] for x in range(0, len(front), 100)]
93-
for chunk in chunks:
91+
for chunk in batch_iter(front, 100):
9492
clause, args = make_in_list_sql_clause(
9593
txn.database_engine, "event_id", chunk
9694
)
97-
txn.execute(base_sql + clause, list(args))
98-
new_front.update([r[0] for r in txn])
95+
txn.execute(base_sql + clause, args)
96+
new_front.update(r[0] for r in txn)
9997

10098
new_front -= ignore_events
10199
new_front -= results
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
# Building full schema dumps
1+
# Synapse Database Schemas
22

3-
These schemas need to be made from a database that has had all background updates run.
3+
These schemas are used as a basis to create brand new Synapse databases, on both
4+
SQLite3 and Postgres.
45

5-
To do so, use `scripts-dev/make_full_schema.sh`. This will produce
6-
`full.sql.postgres ` and `full.sql.sqlite` files.
6+
## Building full schema dumps
7+
8+
If you want to recreate these schemas, they need to be made from a database that
9+
has had all background updates run.
10+
11+
To do so, use `scripts-dev/make_full_schema.sh`. This will produce new
12+
`full.sql.postgres ` and `full.sql.sqlite` files.
713

814
Ensure postgres is installed and your user has the ability to run bash commands
9-
such as `createdb`.
15+
such as `createdb`, then call
16+
17+
./scripts-dev/make_full_schema.sh -p postgres_username -o output_dir/
1018

11-
```
12-
./scripts-dev/make_full_schema.sh -p postgres_username -o output_dir/
13-
```
19+
There are currently two folders with full-schema snapshots. `16` is a snapshot
20+
from 2015, for historical reference. The other contains the most recent full
21+
schema snapshot.

synapse/storage/database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ def simple_search_list_txn(cls, txn, table, term, col, retcols):
15041504

15051505
def make_in_list_sql_clause(
15061506
database_engine, column: str, iterable: Iterable
1507-
) -> Tuple[str, Iterable]:
1507+
) -> Tuple[str, list]:
15081508
"""Returns an SQL clause that checks the given column is in the iterable.
15091509
15101510
On SQLite this expands to `column IN (?, ?, ...)`, whereas on Postgres

0 commit comments

Comments
 (0)