From f8e91a10e8258709119416b884ab7afad680dffa Mon Sep 17 00:00:00 2001 From: rr- Date: Sat, 27 Aug 2016 01:18:03 +0200 Subject: [PATCH] server/search: refactor query factories --- server/szurubooru/search/configs/base_search_config.py | 8 ++++---- server/szurubooru/search/configs/comment_search_config.py | 6 ++++++ server/szurubooru/search/configs/post_search_config.py | 2 +- .../szurubooru/search/configs/snapshot_search_config.py | 6 ++++++ server/szurubooru/search/configs/tag_search_config.py | 5 ++++- server/szurubooru/search/configs/user_search_config.py | 8 ++++++-- 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/server/szurubooru/search/configs/base_search_config.py b/server/szurubooru/search/configs/base_search_config.py index 4ee23b3e..342bdad9 100644 --- a/server/szurubooru/search/configs/base_search_config.py +++ b/server/szurubooru/search/configs/base_search_config.py @@ -11,11 +11,11 @@ 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() + raise NotImplementedError() + + def create_around_query(self): + raise NotImplementedError() @property def id_column(self): diff --git a/server/szurubooru/search/configs/comment_search_config.py b/server/szurubooru/search/configs/comment_search_config.py index 693ccb80..6f19aed9 100644 --- a/server/szurubooru/search/configs/comment_search_config.py +++ b/server/szurubooru/search/configs/comment_search_config.py @@ -8,6 +8,12 @@ class CommentSearchConfig(BaseSearchConfig): def create_filter_query(self): return db.session.query(db.Comment).join(db.User) + def create_count_query(self): + return self.create_filter_query() + + def create_around_query(self): + raise NotImplementedError() + def finalize_query(self, query): return query.order_by(db.Comment.creation_time.desc()) diff --git a/server/szurubooru/search/configs/post_search_config.py b/server/szurubooru/search/configs/post_search_config.py index aec5c23b..7036c0ca 100644 --- a/server/szurubooru/search/configs/post_search_config.py +++ b/server/szurubooru/search/configs/post_search_config.py @@ -104,7 +104,7 @@ class PostSearchConfig(BaseSearchConfig): return db.session.query(db.Post.post_id) def create_filter_query(self): - return self.create_count_query() \ + return db.session.query(db.Post) \ .options( # use config optimized for official client # defer(db.Post.score), diff --git a/server/szurubooru/search/configs/snapshot_search_config.py b/server/szurubooru/search/configs/snapshot_search_config.py index 6b1d51a8..d7705ab5 100644 --- a/server/szurubooru/search/configs/snapshot_search_config.py +++ b/server/szurubooru/search/configs/snapshot_search_config.py @@ -7,6 +7,12 @@ class SnapshotSearchConfig(BaseSearchConfig): def create_filter_query(self): return db.session.query(db.Snapshot) + def create_count_query(self): + return db.session.query(db.Snapshot) + + def create_around_query(self): + raise NotImplementedError() + def finalize_query(self, query): return query.order_by(db.Snapshot.creation_time.desc()) diff --git a/server/szurubooru/search/configs/tag_search_config.py b/server/szurubooru/search/configs/tag_search_config.py index 615c8d02..40f57e6e 100644 --- a/server/szurubooru/search/configs/tag_search_config.py +++ b/server/szurubooru/search/configs/tag_search_config.py @@ -8,7 +8,7 @@ from szurubooru.search.configs.base_search_config import BaseSearchConfig class TagSearchConfig(BaseSearchConfig): def create_filter_query(self): - return self.create_count_query() \ + return db.session.query(db.Tag) \ .join(db.TagCategory) \ .options( subqueryload(db.Tag.names), @@ -19,6 +19,9 @@ class TagSearchConfig(BaseSearchConfig): def create_count_query(self): return db.session.query(db.Tag) + def create_around_query(self): + raise NotImplementedError() + def finalize_query(self, query): return query.order_by(db.Tag.first_name.asc()) diff --git a/server/szurubooru/search/configs/user_search_config.py b/server/szurubooru/search/configs/user_search_config.py index 8fb31dad..944f5dc8 100644 --- a/server/szurubooru/search/configs/user_search_config.py +++ b/server/szurubooru/search/configs/user_search_config.py @@ -5,11 +5,15 @@ from szurubooru.search.configs.base_search_config import BaseSearchConfig class UserSearchConfig(BaseSearchConfig): - ''' Executes searches related to the users. ''' - def create_filter_query(self): return db.session.query(db.User) + def create_count_query(self): + return db.session.query(db.User) + + def create_around_query(self): + raise NotImplementedError() + def finalize_query(self, query): return query.order_by(db.User.name.asc())