summary refs log tree commit diff
path: root/synapse/storage/databases
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2020-08-11 18:00:17 +0100
committerErik Johnston <erik@matrix.org>2020-08-11 18:00:17 +0100
commit0f1afbe8dc853c8726de797ede10cad2fe336b16 (patch)
treeb80df118d1c2a0a35fb745b47153284a9f97a9aa /synapse/storage/databases
parentMerge remote-tracking branch 'origin/master' into develop (diff)
downloadsynapse-0f1afbe8dc853c8726de797ede10cad2fe336b16.tar.xz
Change HomeServer definition to work with typing.
Duplicating function signatures between server.py and server.pyi is
silly. This commit changes that by changing all `build_*` methods to
`get_*` methods and changing the `_make_dependency_method` to work work
as a descriptor that caches the produced value.

There are some changes in other files that were made to fix the typing
in server.py.
Diffstat (limited to 'synapse/storage/databases')
-rw-r--r--synapse/storage/databases/__init__.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/synapse/storage/databases/__init__.py b/synapse/storage/databases/__init__.py
index b163eebf39..4406e58273 100644
--- a/synapse/storage/databases/__init__.py
+++ b/synapse/storage/databases/__init__.py
@@ -38,9 +38,9 @@ class Databases(object):
         # store.
 
         self.databases = []
-        self.main = None
-        self.state = None
-        self.persist_events = None
+        main = None
+        state = None
+        persist_events = None
 
         for database_config in hs.config.database.databases:
             db_name = database_config.name
@@ -61,27 +61,25 @@ class Databases(object):
 
                     # Sanity check we don't try and configure the main store on
                     # multiple databases.
-                    if self.main:
+                    if main:
                         raise Exception("'main' data store already configured")
 
-                    self.main = main_store_class(database, db_conn, hs)
+                    main = main_store_class(database, db_conn, hs)
 
                     # If we're on a process that can persist events also
                     # instantiate a `PersistEventsStore`
                     if hs.config.worker.writers.events == hs.get_instance_name():
-                        self.persist_events = PersistEventsStore(
-                            hs, database, self.main
-                        )
+                        persist_events = PersistEventsStore(hs, database, main)
 
                 if "state" in database_config.databases:
                     logger.info("Starting 'state' data store")
 
                     # Sanity check we don't try and configure the state store on
                     # multiple databases.
-                    if self.state:
+                    if state:
                         raise Exception("'state' data store already configured")
 
-                    self.state = StateGroupDataStore(database, db_conn, hs)
+                    state = StateGroupDataStore(database, db_conn, hs)
 
                 db_conn.commit()
 
@@ -90,8 +88,14 @@ class Databases(object):
                 logger.info("Database %r prepared", db_name)
 
         # Sanity check that we have actually configured all the required stores.
-        if not self.main:
+        if not main:
             raise Exception("No 'main' data store configured")
 
-        if not self.state:
+        if not state:
             raise Exception("No 'main' data store configured")
+
+        # We use local variables here to ensure that the databases do not have
+        # optional types.
+        self.main = main
+        self.state = state
+        self.persist_events = persist_events