Rev1754, Don't reload domain database on very request

This commit is contained in:
shortcutme 2016-11-19 10:56:19 +01:00
parent a5290288c7
commit bbbfffd1cb
2 changed files with 16 additions and 4 deletions

View file

@ -1,5 +1,6 @@
import logging
import re
import time
from Config import config
from Plugin import PluginManager
@ -12,6 +13,8 @@ log = logging.getLogger("ZeronamePlugin")
@PluginManager.registerTo("SiteManager")
class SiteManagerPlugin(object):
site_zeroname = None
db_domains = None
db_domains_modified = None
def load(self, *args, **kwargs):
super(SiteManagerPlugin, self).load(*args, **kwargs)
@ -35,9 +38,18 @@ class SiteManagerPlugin(object):
domain = domain.lower()
if not self.site_zeroname:
self.site_zeroname = self.need(config.bit_resolver)
self.site_zeroname.needFile("data/names.json", priority=10)
db = self.site_zeroname.storage.loadJson("data/names.json")
return db.get(domain)
site_zeroname_modified = self.site_zeroname.content_manager.contents.get("content.json", {}).get("modified", 0)
if not self.db_domains or self.db_domains_modified != site_zeroname_modified:
self.site_zeroname.needFile("data/names.json", priority=10)
s = time.time()
self.db_domains = self.site_zeroname.storage.loadJson("data/names.json")
log.debug(
"Domain db with %s entries loaded in %.3fs (modification: %s -> %s)" %
(len(self.db_domains), time.time() - s, self.db_domains_modified, site_zeroname_modified)
)
self.db_domains_modified = site_zeroname_modified
return self.db_domains.get(domain)
# Return or create site and start download site files
# Return: Site or None if dns resolve failed

View file

@ -9,7 +9,7 @@ class Config(object):
def __init__(self, argv):
self.version = "0.5.1"
self.rev = 1751
self.rev = 1754
self.argv = argv
self.action = None
self.config_file = "zeronet.conf"