mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-11 12:42:34 +01:00
structures: directly retrieve DB save delay in DataStore (#303)
This commit is contained in:
parent
b0636b40ab
commit
b94e11930e
@ -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
|
||||
|
||||
|
@ -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'],
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user