server/search: refactor query factories
This commit is contained in:
parent
8f230f5701
commit
f8e91a10e8
6 changed files with 27 additions and 8 deletions
|
@ -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):
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
Loading…
Reference in a new issue