fix cache, lookup
This commit is contained in:
parent
784a29866c
commit
b6f5e9c0cc
4 changed files with 18 additions and 7 deletions
|
@ -13,6 +13,8 @@ from . import worldcat
|
|||
from . import google
|
||||
from . import duckduckgo
|
||||
|
||||
from oml import settings
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -84,6 +86,9 @@ def lookup(key, value):
|
|||
data[k] = []
|
||||
if v not in data[k]:
|
||||
data[k].append(v)
|
||||
for key in [k['id'] for k in settings.config['itemKeys'] if isinstance(k['type'], list)]:
|
||||
if key in data and not isinstance(data[key], list):
|
||||
data[key] = [data[key]]
|
||||
return data
|
||||
|
||||
def isvalid_id(key, value):
|
||||
|
|
|
@ -7,6 +7,8 @@ from urllib.parse import urlencode
|
|||
|
||||
from ox.cache import read_url
|
||||
|
||||
import settings
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -28,4 +30,8 @@ def find(query):
|
|||
|
||||
def lookup(key, value):
|
||||
logger.debug('lookup %s %s', key, value)
|
||||
return request('getMetadata', {key: value})
|
||||
data = request('getMetadata', {key: value})
|
||||
for key in [k['id'] for k in settings.config['itemKeys'] if isinstance(k['type'], list)]:
|
||||
if key in data and not isinstance(data[key], list):
|
||||
data[key] = [data[key]]
|
||||
return data
|
||||
|
|
|
@ -5,8 +5,8 @@ import json
|
|||
import os
|
||||
import ed25519
|
||||
|
||||
from pdict import pdict
|
||||
from utils import get_user_id
|
||||
from oml.pdict import pdict
|
||||
from oml.utils import get_user_id
|
||||
|
||||
base_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..'))
|
||||
static_path = os.path.join(base_dir, 'static')
|
||||
|
@ -34,7 +34,7 @@ else:
|
|||
|
||||
preferences = pdict(os.path.join(config_path, 'preferences.json'), config['user']['preferences'])
|
||||
ui = pdict(os.path.join(config_path, 'ui.json'), config['user']['ui'])
|
||||
lists_cache = pdict(os.path.join(config_path, 'lists_cache.json'), {})
|
||||
list_cache = pdict(os.path.join(config_path, 'list_cache.json'), {})
|
||||
|
||||
server = pdict(os.path.join(config_path, 'server.json'))
|
||||
server_defaults = {
|
||||
|
|
|
@ -302,8 +302,8 @@ class List(db.Model):
|
|||
|
||||
def items_count(self):
|
||||
key = self.find_id
|
||||
if key in settings.lists_cache:
|
||||
value = settings.lists_cache[key]
|
||||
if key in settings.list_cache:
|
||||
value = settings.list_cache[key]
|
||||
else:
|
||||
from item.models import Item
|
||||
if self._query:
|
||||
|
@ -311,7 +311,7 @@ class List(db.Model):
|
|||
value = Parser(Item).find({'query': data}).count()
|
||||
else:
|
||||
value = len(self.items)
|
||||
settings.lists_cache[key] = value
|
||||
settings.list_cache[key] = value
|
||||
return value
|
||||
|
||||
def json(self):
|
||||
|
|
Loading…
Reference in a new issue