From b94e11930eb2a47c0045a571665fe34cef915766 Mon Sep 17 00:00:00 2001 From: James Lu Date: Wed, 9 Nov 2016 22:52:46 -0800 Subject: [PATCH] structures: directly retrieve DB save delay in DataStore (#303) --- plugins/automode.py | 3 +-- plugins/relay.py | 4 +--- structures.py | 7 ++++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/plugins/automode.py b/plugins/automode.py index 8c512e0..95c70c5 100644 --- a/plugins/automode.py +++ b/plugins/automode.py @@ -19,8 +19,7 @@ reply = modebot.reply # Databasing variables. dbname = utils.getDatabaseName('automode') -save_delay = conf.conf['bot'].get('save_delay', 300) -datastore = structures.JSONDataStore('automode', dbname, save_frequency=save_delay, default_db=collections.defaultdict(dict)) +datastore = structures.JSONDataStore('automode', dbname, default_db=collections.defaultdict(dict)) db = datastore.store diff --git a/plugins/relay.py b/plugins/relay.py index ffe6725..3e77526 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -15,10 +15,8 @@ relayservers = defaultdict(dict) spawnlocks = defaultdict(threading.RLock) spawnlocks_servers = defaultdict(threading.RLock) -save_delay = conf.conf['bot'].get('save_delay', 300) - dbname = utils.getDatabaseName('pylinkrelay') -datastore = structures.PickleDataStore('pylinkrelay', dbname, save_frequency=save_delay) +datastore = structures.PickleDataStore('pylinkrelay', dbname) db = datastore.store default_permissions = {"*!*@*": ['relay.linked'], diff --git a/structures.py b/structures.py index bfe9d01..8bc0055 100644 --- a/structures.py +++ b/structures.py @@ -11,6 +11,7 @@ import os import threading from .log import log +from . import conf class KeyedDefaultdict(collections.defaultdict): """ @@ -29,14 +30,14 @@ class DataStore: Generic database class. Plugins should use a subclass of this such as JSONDataStore or PickleDataStore. """ - def __init__(self, name, filename, save_frequency=30, default_db=None): + def __init__(self, name, filename, save_frequency=None, default_db=None): self.name = name self.filename = filename self.tmp_filename = filename + '.tmp' log.debug('(DataStore:%s) database path set to %s', self.name, self.filename) - self.save_frequency = save_frequency + self.save_frequency = save_frequency or conf.conf['bot'].get('save_delay', 300) log.debug('(DataStore:%s) saving every %s seconds', self.name, self.save_frequency) if default_db is not None: @@ -48,7 +49,7 @@ class DataStore: self.load() - if save_frequency > 0: + if self.save_frequency > 0: # If autosaving is enabled, start the save_callback loop. self.save_callback(starting=True)