def __init__(self, database: DatabasePool, db_conn, hs): self.services_cache = load_appservices( hs.hostname, hs.config.app_service_config_files ) self.exclusive_user_regex = _make_exclusive_regex(self.services_cache) super().__init__(database, db_conn, hs)
def __init__(self, db_conn, hs): self.services_cache = load_appservices( hs.hostname, hs.config.app_service_config_files ) self.exclusive_user_regex = _make_exclusive_regex(self.services_cache) super(ApplicationServiceWorkerStore, self).__init__(db_conn, hs)
def __init__( self, database: DatabasePool, db_conn: LoggingDatabaseConnection, hs: "HomeServer", ): self.services_cache = load_appservices( hs.hostname, hs.config.appservice.app_service_config_files) self.exclusive_user_regex = _make_exclusive_regex(self.services_cache) def get_max_as_txn_id(txn: Cursor) -> int: logger.warning( "Falling back to slow query, you should port to postgres") txn.execute( "SELECT COALESCE(max(txn_id), 0) FROM application_services_txns" ) return cast(Tuple[int], txn.fetchone())[0] self._as_txn_seq_gen = build_sequence_generator( db_conn, database.engine, get_max_as_txn_id, "application_services_txn_id_seq", table="application_services_txns", id_column="txn_id", ) super().__init__(database, db_conn, hs)
def run_upgrade(cur, database_engine, config, *args, **kwargs): cur.execute("SELECT name FROM users") rows = cur.fetchall() config_files = [] try: config_files = config.app_service_config_files except AttributeError: logger.warning("Could not get app_service_config_files from config") pass appservices = load_appservices(config.server_name, config_files) owned = {} for row in rows: user_id = row[0] for appservice in appservices: if appservice.is_exclusive_user(user_id): if user_id in owned.keys(): logger.error( "user_id %s was owned by more than one application" " service (IDs %s and %s); assigning arbitrarily to %s" % (user_id, owned[user_id], appservice.id, owned[user_id])) owned.setdefault(appservice.id, []).append(user_id) for as_id, user_ids in owned.items(): n = 100 user_chunks = (user_ids[i:i + 100] for i in range(0, len(user_ids), n)) for chunk in user_chunks: cur.execute( database_engine.convert_param_style( "UPDATE users SET appservice_id = ? WHERE name IN (%s)" % (",".join("?" for _ in chunk), )), [as_id] + chunk)
def __init__(self, hs): super(ApplicationServiceStore, self).__init__(hs) self.hostname = hs.hostname self.services_cache = load_appservices( hs.hostname, hs.config.app_service_config_files )
def run_upgrade(cur, database_engine, config, *args, **kwargs): cur.execute("SELECT name FROM users") rows = cur.fetchall() config_files = [] try: config_files = config.app_service_config_files except AttributeError: logger.warning("Could not get app_service_config_files from config") pass appservices = load_appservices( config.server_name, config_files ) owned = {} for row in rows: user_id = row[0] for appservice in appservices: if appservice.is_exclusive_user(user_id): if user_id in owned.keys(): logger.error( "user_id %s was owned by more than one application" " service (IDs %s and %s); assigning arbitrarily to %s" % (user_id, owned[user_id], appservice.id, owned[user_id]) ) owned.setdefault(appservice.id, []).append(user_id) for as_id, user_ids in owned.items(): n = 100 user_chunks = (user_ids[i:i + 100] for i in xrange(0, len(user_ids), n)) for chunk in user_chunks: cur.execute( database_engine.convert_param_style( "UPDATE users SET appservice_id = ? WHERE name IN (%s)" % ( ",".join("?" for _ in chunk), ) ), [as_id] + chunk )
def __init__(self, db_conn, hs): super(SlavedApplicationServiceStore, self).__init__(db_conn, hs) self.services_cache = load_appservices( hs.config.server_name, hs.config.app_service_config_files )
def __init__(self, db_conn, hs): super(SlavedApplicationServiceStore, self).__init__(db_conn, hs) self.services_cache = load_appservices( hs.config.server_name, hs.config.app_service_config_files)