Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use memcache #393

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion common/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time
import json

from pymemcache.client.base import Client
from pathlib import Path
from common.lib.database import Database

Expand All @@ -17,6 +18,7 @@ class ConfigManager:
db = None
dbconn = None
cache = {}
memcache = None

core_settings = {}
config_definition = {}
Expand All @@ -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):
"""
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions common/lib/config_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"psutil~=5.0",
"psycopg2~=2.9.0",
"pyahocorasick~=1.4.0",
"pymemcache",
"PyMySQL~=1.0",
"PyTumblr==0.1.0",
"requests~=2.27",
Expand Down
Loading