From 28009bf46d15f2b9bcbbb91e6c0fd7b1a647766d Mon Sep 17 00:00:00 2001 From: rr- Date: Thu, 2 Jun 2016 23:39:26 +0200 Subject: [PATCH] server/general: fix pylint warnings --- server/szurubooru/func/cache.py | 27 ++++++++----------- server/szurubooru/middleware/cache_purger.py | 1 - .../szurubooru/search/base_search_config.py | 3 +-- server/szurubooru/search/search_executor.py | 6 ++--- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/server/szurubooru/func/cache.py b/server/szurubooru/func/cache.py index 0dfeeb43..34a506c1 100644 --- a/server/szurubooru/func/cache.py +++ b/server/szurubooru/func/cache.py @@ -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)) diff --git a/server/szurubooru/middleware/cache_purger.py b/server/szurubooru/middleware/cache_purger.py index 636e6b02..b8daa880 100644 --- a/server/szurubooru/middleware/cache_purger.py +++ b/server/szurubooru/middleware/cache_purger.py @@ -1,4 +1,3 @@ -import falcon from szurubooru.func import cache class CachePurger(object): diff --git a/server/szurubooru/search/base_search_config.py b/server/szurubooru/search/base_search_config.py index 9b4d06f0..3830768e 100644 --- a/server/szurubooru/search/base_search_config.py +++ b/server/szurubooru/search/base_search_config.py @@ -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: diff --git a/server/szurubooru/search/search_executor.py b/server/szurubooru/search/search_executor.py index ec4c2052..d23b2888 100644 --- a/server/szurubooru/search/search_executor.py +++ b/server/szurubooru/search/search_executor.py @@ -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)