server/general: fix pylint warnings
This commit is contained in:
parent
7c7adafd82
commit
28009bf46d
4 changed files with 15 additions and 22 deletions
|
@ -15,8 +15,12 @@ class LruCache(object):
|
|||
|
||||
def insert_item(self, item):
|
||||
if item.key in self.hash:
|
||||
item_index = next(i for i, v in enumerate(self.item_list) if v.key == item.key)
|
||||
self.item_list[:] = self.item_list[:item_index] + self.item_list[item_index+1:]
|
||||
item_index = next(i \
|
||||
for i, v in enumerate(self.item_list) \
|
||||
if v.key == item.key)
|
||||
self.item_list[:] \
|
||||
= self.item_list[:item_index] \
|
||||
+ self.item_list[item_index+1:]
|
||||
self.item_list.insert(0, item)
|
||||
else:
|
||||
if len(self.item_list) > self.length:
|
||||
|
@ -32,25 +36,16 @@ class LruCache(object):
|
|||
del self.hash[item.key]
|
||||
del self.item_list[self.item_list.index(item)]
|
||||
|
||||
def validate_item(self):
|
||||
def _outdated_items():
|
||||
now = datetime.now()
|
||||
for item in self.item_list:
|
||||
time_delta = now - item.timestamp
|
||||
if time_delta.seconds > self.delta:
|
||||
yield item
|
||||
map(lambda x: self.remove_item(x), _outdated_items())
|
||||
|
||||
_cache = LruCache(length=100)
|
||||
_CACHE = LruCache(length=100)
|
||||
|
||||
def purge():
|
||||
_cache.remove_all()
|
||||
_CACHE.remove_all()
|
||||
|
||||
def has(key):
|
||||
return key in _cache.hash
|
||||
return key in _CACHE.hash
|
||||
|
||||
def get(key):
|
||||
return _cache.hash[key].value
|
||||
return _CACHE.hash[key].value
|
||||
|
||||
def put(key, value):
|
||||
_cache.insert_item(LruCacheItem(key, value))
|
||||
_CACHE.insert_item(LruCacheItem(key, value))
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import falcon
|
||||
from szurubooru.func import cache
|
||||
|
||||
class CachePurger(object):
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import sqlalchemy
|
||||
import szurubooru.errors
|
||||
from szurubooru import db, errors
|
||||
from szurubooru.func import util
|
||||
from szurubooru.search import criteria
|
||||
|
@ -55,7 +54,7 @@ class BaseSearchConfig(object):
|
|||
expr = column <= int(criterion.max_value)
|
||||
else:
|
||||
assert False
|
||||
except ValueError as e:
|
||||
except ValueError:
|
||||
raise errors.SearchError(
|
||||
'Criterion value %r must be a number.' % (criterion,))
|
||||
if criterion.negated:
|
||||
|
|
|
@ -14,13 +14,13 @@ class SearchExecutor(object):
|
|||
self.config = search_config
|
||||
|
||||
def execute(self, query_text, page, page_size):
|
||||
key = (id(self.config), query_text, page, page_size)
|
||||
if cache.has(key):
|
||||
return cache.get(key)
|
||||
'''
|
||||
Parse input and return tuple containing total record count and filtered
|
||||
entities.
|
||||
'''
|
||||
key = (id(self.config), query_text, page, page_size)
|
||||
if cache.has(key):
|
||||
return cache.get(key)
|
||||
filter_query = self.config.create_filter_query()
|
||||
filter_query = filter_query.options(sqlalchemy.orm.lazyload('*'))
|
||||
filter_query = self._prepare(filter_query, query_text)
|
||||
|
|
Loading…
Reference in a new issue