From 36eddad424139c8d9619b0f5e73469d9a76276e7 Mon Sep 17 00:00:00 2001 From: rr- Date: Mon, 13 Jun 2016 23:56:59 +0200 Subject: [PATCH] server/posts: optimize 'posts around' query --- server/szurubooru/search/configs/base_search_config.py | 3 +++ server/szurubooru/search/configs/post_search_config.py | 3 +++ server/szurubooru/search/executor.py | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/server/szurubooru/search/configs/base_search_config.py b/server/szurubooru/search/configs/base_search_config.py index bb2cc0b1..350a54a8 100644 --- a/server/szurubooru/search/configs/base_search_config.py +++ b/server/szurubooru/search/configs/base_search_config.py @@ -10,6 +10,9 @@ class BaseSearchConfig(object): def create_filter_query(self): raise NotImplementedError() + def create_around_query(self): + return self.create_filter_query() + def create_count_query(self): return self.create_filter_query() diff --git a/server/szurubooru/search/configs/post_search_config.py b/server/szurubooru/search/configs/post_search_config.py index 4e4f69bb..686df4ff 100644 --- a/server/szurubooru/search/configs/post_search_config.py +++ b/server/szurubooru/search/configs/post_search_config.py @@ -78,6 +78,9 @@ class PostSearchConfig(BaseSearchConfig): new_special_tokens.append(token) search_query.special_tokens = new_special_tokens + def create_around_query(self): + return db.session.query(db.Post.post_id) + def create_filter_query(self): return self.create_count_query() \ .options( diff --git a/server/szurubooru/search/executor.py b/server/szurubooru/search/executor.py index 6df508af..13238632 100644 --- a/server/szurubooru/search/executor.py +++ b/server/szurubooru/search/executor.py @@ -31,7 +31,7 @@ class Executor(object): search_query = self.parser.parse(query_text) self.config.on_search_query_parsed(search_query) filter_query = self.config \ - .create_filter_query() \ + .create_around_query() \ .options(sqlalchemy.orm.lazyload('*')) filter_query = self._prepare_db_query(filter_query, search_query, False) prev_filter_query = filter_query \