From 83f62b03786ae30a39238efba296b0e7f78949cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 17 Jun 2019 12:26:38 +0200 Subject: [PATCH] config: Make additional Homeserver requests for the search endpoint optional. --- docs/man/pantalaimon.5 | 15 +++++++++++++++ pantalaimon/client.py | 4 +++- pantalaimon/config.py | 6 +++++- pantalaimon/daemon.py | 2 ++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/docs/man/pantalaimon.5 b/docs/man/pantalaimon.5 index 9f13eee..216afc7 100644 --- a/docs/man/pantalaimon.5 +++ b/docs/man/pantalaimon.5 @@ -51,6 +51,21 @@ This option configures if a proxy instance should use the OS keyring to store its own access tokens. The access tokens are required for the daemon to resume operation. If this is set to "No", access tokens are stored in the pantalaimon database in plaintext. Defaults to "Yes". +.It Cm SearchRequests +This option configures if the proxy should make additional HTTP requests to the +server when clients use the search API endpoint. Some data that is required to +fill out a complete search response is only available on the Homeserver (e.g. +start/end tokens for the event context or room state at a particular point in +time). + +If this option is set to "On" +.Nm pantalaimon +will make additional HTTP requests to fetch the unavailable data from the +Homeserver, note that this will make the search much slower. If this is set to +"Off" +.Nm pantalaimon +will not make any additional HTTP requests and will leave some data fields in +the search response empty. Defaults to "Off". .El .Pp Aditional to the homeserver section a special section with the name diff --git a/pantalaimon/client.py b/pantalaimon/client.py index b17925d..a8e2143 100644 --- a/pantalaimon/client.py +++ b/pantalaimon/client.py @@ -114,6 +114,7 @@ class PanClient(AsyncClient): self, server_name, pan_store, + pan_conf, homeserver, queue=None, user_id="", @@ -136,6 +137,7 @@ class PanClient(AsyncClient): self.server_name = server_name self.pan_store = pan_store + self.pan_conf = pan_conf self.index = IndexStore(self.user_id, index_dir) self.task = None self.queue = queue @@ -745,7 +747,7 @@ class PanClient(AsyncClient): after_limit=after_limit ) - if event_context or include_state: + if (event_context or include_state) and self.pan_conf.search_requests: for event_dict in response_dict["results"]: await add_context( event_dict, diff --git a/pantalaimon/config.py b/pantalaimon/config.py index 2cf36a5..7e0f8ac 100644 --- a/pantalaimon/config.py +++ b/pantalaimon/config.py @@ -34,6 +34,7 @@ class PanConfigParser(configparser.ConfigParser): "LogLevel": "warnig", "Notifications": "on", "UseKeyring": "yes", + "SearchRequests": "off", }, converters={ "address": parse_address, @@ -112,6 +113,7 @@ class ServerConfig: ssl = attr.ib(type=bool, default=True) ignore_verification = attr.ib(type=bool, default=False) keyring = attr.ib(type=bool, default=True) + search_requests = attr.ib(type=bool, default=False) @attr.s @@ -168,6 +170,7 @@ class PanConfig: ignore_verification = section.getboolean("IgnoreVerification") keyring = section.getboolean("UseKeyring") proxy = section.geturl("Proxy") + search_requests = section.getboolean("SearchRequests") listen_tuple = (listen_address, listen_port) @@ -185,7 +188,8 @@ class PanConfig: proxy, ssl, ignore_verification, - keyring + keyring, + search_requests ) self.servers[section_name] = server_conf diff --git a/pantalaimon/daemon.py b/pantalaimon/daemon.py index 1d7d82e..8c1c6e5 100755 --- a/pantalaimon/daemon.py +++ b/pantalaimon/daemon.py @@ -100,6 +100,7 @@ class ProxyDaemon: pan_client = PanClient( self.name, self.store, + self.conf, self.homeserver_url, self.send_queue, user_id, @@ -518,6 +519,7 @@ class ProxyDaemon: pan_client = PanClient( self.name, self.store, + self.conf, self.homeserver_url, self.send_queue, user_id,