config: Make additional Homeserver requests for the search endpoint optional.

This commit is contained in:
Damir Jelić 2019-06-17 12:26:38 +02:00
parent a6a62434e0
commit 83f62b0378
4 changed files with 25 additions and 2 deletions

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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,