From 3b70e2c1468e04882ca3779badbc4e1ff0b67fa6 Mon Sep 17 00:00:00 2001 From: Stijn Peeters Date: Mon, 23 Oct 2023 17:10:23 +0200 Subject: [PATCH 1/2] Add python-memcached to setup.py --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 7eff86382..44ab593b2 100644 --- a/setup.py +++ b/setup.py @@ -43,6 +43,7 @@ "psycopg2~=2.9.0", "pyahocorasick~=1.4.0", "PyMySQL~=1.0", + "python-memcached", "PyTumblr==0.1.0", "requests~=2.27", "requests_futures", From ee5c9d318534db8a43d38e89a1f38a80b8eb798d Mon Sep 17 00:00:00 2001 From: Stijn Peeters Date: Tue, 24 Oct 2023 11:31:35 +0200 Subject: [PATCH 2/2] Initialise on config load --- common/config_manager.py | 11 ++++++++++- common/lib/config_definition.py | 7 +++++++ setup.py | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/common/config_manager.py b/common/config_manager.py index 9f76ce7ac..c0966321e 100644 --- a/common/config_manager.py +++ b/common/config_manager.py @@ -2,6 +2,7 @@ import time import json +from pymemcache.client.base import Client from pathlib import Path from common.lib.database import Database @@ -17,6 +18,7 @@ class ConfigManager: db = None dbconn = None cache = {} + memcache = None core_settings = {} config_definition = {} @@ -28,7 +30,8 @@ def __init__(self, db=None): self.load_user_settings() # establish database connection if none available - self.db = db + if db: + self.with_db(db) def with_db(self, db=None): """ @@ -43,6 +46,12 @@ def with_db(self, db=None): password=self.get("DB_PASSWORD"), host=self.get("DB_HOST"), port=self.get("DB_PORT"), appname="config-reader") if not db else db + # now we have a database connection, we can initialise the memcached + # client (since the address is stored in the database) + memcache_address = self.get("4cat.memcached_server") + if memcache_address: + self.memcache = Client(memcache_address) + def load_user_settings(self): """ Load settings configurable by the user diff --git a/common/lib/config_definition.py b/common/lib/config_definition.py index c92e7c4be..df768da2f 100644 --- a/common/lib/config_definition.py +++ b/common/lib/config_definition.py @@ -233,6 +233,13 @@ "tooltip": "Sphinx is used for full-text search for collected datasources (e.g., 4chan, 8kun, 8chan) and requires additional setup (see 4CAT wiki on GitHub).", "global": True }, + "4cat.memcached_host": { + "type": UserInput.OPTION_TEXT, + "default": "", + "help": "Memcached server", + "tooltip": "Memcached server address, e.g. 'localhost' or '127.0.0.1:11211. If empty, memcached is not used.", + "global": True + }, "logging.slack.level": { "type": UserInput.OPTION_CHOICE, "default": "WARNING", diff --git a/setup.py b/setup.py index 44ab593b2..3c3532618 100644 --- a/setup.py +++ b/setup.py @@ -42,8 +42,8 @@ "psutil~=5.0", "psycopg2~=2.9.0", "pyahocorasick~=1.4.0", + "pymemcache", "PyMySQL~=1.0", - "python-memcached", "PyTumblr==0.1.0", "requests~=2.27", "requests_futures",