You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2021/03/28 18:59:27 UTC
[incubator-ponymail-foal] branch master updated: use dburl if
present, refactor ES connection
This is an automated email from the ASF dual-hosted git repository.
humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git
The following commit(s) were added to refs/heads/master by this push:
new e004fba use dburl if present, refactor ES connection
e004fba is described below
commit e004fba08ebf83f75be494671bb2772fa4f96f54
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Sun Mar 28 20:59:22 2021 +0200
use dburl if present, refactor ES connection
---
server/plugins/background.py | 38 ++++++++++++++++++--------------------
1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/server/plugins/background.py b/server/plugins/background.py
index d7418fb..0f2afac 100644
--- a/server/plugins/background.py
+++ b/server/plugins/background.py
@@ -32,6 +32,22 @@ class ProgTimer:
print("Done in %.2f seconds" % (time.time() - self.start))
+def es_connector(database: plugins.configuration.DBConfig) -> AsyncElasticsearch:
+ if database.dburl:
+ return AsyncElasticsearch([database.dburl])
+ else:
+ return AsyncElasticsearch(
+ [
+ {
+ "host": database.hostname,
+ "port": database.port,
+ "url_prefix": database.url_prefix or "",
+ "use_ssl": database.secure,
+ },
+ ]
+ )
+
+
async def get_lists(database: plugins.configuration.DBConfig) -> dict:
"""
@@ -40,16 +56,7 @@ async def get_lists(database: plugins.configuration.DBConfig) -> dict:
public or private
"""
lists = {}
- client = AsyncElasticsearch(
- [
- {
- "host": database.hostname,
- "port": database.port,
- "url_prefix": database.url_prefix or "",
- "use_ssl": database.secure,
- },
- ]
- )
+ client = es_connector(database)
# Fetch aggregations of all public emails
s = Search(using=client, index=database.db_prefix + "-mbox").query(
@@ -95,16 +102,7 @@ async def get_public_activity(database: plugins.configuration.DBConfig) -> dict:
:param database: a PyPony database configuration
:return: A dictionary with activity stats
"""
- client = AsyncElasticsearch(
- [
- {
- "host": database.hostname,
- "port": database.port,
- "url_prefix": database.url_prefix or "",
- "use_ssl": database.secure,
- },
- ]
- )
+ client = es_connector(database)
# Fetch aggregations of all public emails
s = (