From f5ffd69a79190bb112fd146039b568f2af931ea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 17 Jun 2019 16:59:54 +0200 Subject: [PATCH] config: Make the batch size for room history fetching configurable. --- docs/man/pantalaimon.5 | 5 ++++- pantalaimon/client.py | 8 +++++--- pantalaimon/config.py | 23 ++++++++++++++++++++++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/docs/man/pantalaimon.5 b/docs/man/pantalaimon.5 index a443ab8..7994336 100644 --- a/docs/man/pantalaimon.5 +++ b/docs/man/pantalaimon.5 @@ -72,7 +72,10 @@ A configuration option to decide if should fetch the history for unencrytped rooms as well as for encrypted ones. If True, only the history for encrypted rooms is fetched and indexed. Search requests for non-encrypted -rooms are forwarded to the Homeserver. +rooms are forwarded to the Homeserver. Defaults to "True". +.It Cm IndexingBatchSize +The number of messages that should be requested from the Homeserver when we +fetch and index messages from the room history. Defaults to 100. .El .Pp Aditional to the homeserver section a special section with the name diff --git a/pantalaimon/client.py b/pantalaimon/client.py index bdf8ea0..f138429 100644 --- a/pantalaimon/client.py +++ b/pantalaimon/client.py @@ -237,9 +237,11 @@ class PanClient(AsyncClient): logger.debug("Fetching room history for {}".format( room.display_name )) - response = await self.room_messages(fetch_task.room_id, - fetch_task.token, - limit=100) + response = await self.room_messages( + fetch_task.room_id, + fetch_task.token, + limit=self.pan_conf.indexing_batch_size + ) except ClientConnectionError: self.history_fetch_queue.put(fetch_task) diff --git a/pantalaimon/config.py b/pantalaimon/config.py index c00786d..6d200ed 100644 --- a/pantalaimon/config.py +++ b/pantalaimon/config.py @@ -36,6 +36,7 @@ class PanConfigParser(configparser.ConfigParser): "UseKeyring": "yes", "SearchRequests": "off", "IndexEncryptedOnly": "True", + "IndexingBatchSize": "100", }, converters={ "address": parse_address, @@ -104,6 +105,17 @@ class ServerConfig: homeserver. ssl (bool): Enable or disable SSL for the connection between pantalaimon and the homeserver. + ignore_verification (bool): Enable or disable device verification for + E2E encrypted messages. + keyring (bool): Enable or disable the OS keyring for the storage of + access tokens. + search_requests (bool): Enable or disable aditional Homeserver requests + for the search API endpoint. + index_encrypted_only (bool): Enable or disable message indexing fro + non-encrypted rooms. + indexing_batch_size (int): The number of messages that should be + requested from the Homeserver when we fetch and index messages from + the room history. """ name = attr.ib(type=str) @@ -116,6 +128,7 @@ class ServerConfig: keyring = attr.ib(type=bool, default=True) search_requests = attr.ib(type=bool, default=False) index_encrypted_only = attr.ib(type=bool, default=True) + indexing_batch_size = attr.ib(type=int, default=100) @attr.s @@ -175,6 +188,13 @@ class PanConfig: search_requests = section.getboolean("SearchRequests") index_encrypted_only = section.getboolean("IndexEncryptedOnly") + indexing_batch_size = section.getint("IndexingBatchSize") + + if not 1 < indexing_batch_size <= 1000: + raise PanConfigError("The indexing batch size needs to be " + "a positive integer between 1 and " + "1000") + listen_tuple = (listen_address, listen_port) if listen_tuple in listen_set: @@ -193,7 +213,8 @@ class PanConfig: ignore_verification, keyring, search_requests, - index_encrypted_only + index_encrypted_only, + indexing_batch_size ) self.servers[section_name] = server_conf