server/search: refactor query factories
This commit is contained in:
parent
8f230f5701
commit
f8e91a10e8
|
@ -11,11 +11,11 @@ class BaseSearchConfig(object):
|
||||||
def create_filter_query(self):
|
def create_filter_query(self):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def create_around_query(self):
|
|
||||||
return self.create_filter_query()
|
|
||||||
|
|
||||||
def create_count_query(self):
|
def create_count_query(self):
|
||||||
return self.create_filter_query()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def create_around_query(self):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def id_column(self):
|
def id_column(self):
|
||||||
|
|
|
@ -8,6 +8,12 @@ class CommentSearchConfig(BaseSearchConfig):
|
||||||
def create_filter_query(self):
|
def create_filter_query(self):
|
||||||
return db.session.query(db.Comment).join(db.User)
|
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):
|
def finalize_query(self, query):
|
||||||
return query.order_by(db.Comment.creation_time.desc())
|
return query.order_by(db.Comment.creation_time.desc())
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ class PostSearchConfig(BaseSearchConfig):
|
||||||
return db.session.query(db.Post.post_id)
|
return db.session.query(db.Post.post_id)
|
||||||
|
|
||||||
def create_filter_query(self):
|
def create_filter_query(self):
|
||||||
return self.create_count_query() \
|
return db.session.query(db.Post) \
|
||||||
.options(
|
.options(
|
||||||
# use config optimized for official client
|
# use config optimized for official client
|
||||||
# defer(db.Post.score),
|
# defer(db.Post.score),
|
||||||
|
|
|
@ -7,6 +7,12 @@ class SnapshotSearchConfig(BaseSearchConfig):
|
||||||
def create_filter_query(self):
|
def create_filter_query(self):
|
||||||
return db.session.query(db.Snapshot)
|
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):
|
def finalize_query(self, query):
|
||||||
return query.order_by(db.Snapshot.creation_time.desc())
|
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):
|
class TagSearchConfig(BaseSearchConfig):
|
||||||
def create_filter_query(self):
|
def create_filter_query(self):
|
||||||
return self.create_count_query() \
|
return db.session.query(db.Tag) \
|
||||||
.join(db.TagCategory) \
|
.join(db.TagCategory) \
|
||||||
.options(
|
.options(
|
||||||
subqueryload(db.Tag.names),
|
subqueryload(db.Tag.names),
|
||||||
|
@ -19,6 +19,9 @@ class TagSearchConfig(BaseSearchConfig):
|
||||||
def create_count_query(self):
|
def create_count_query(self):
|
||||||
return db.session.query(db.Tag)
|
return db.session.query(db.Tag)
|
||||||
|
|
||||||
|
def create_around_query(self):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
def finalize_query(self, query):
|
def finalize_query(self, query):
|
||||||
return query.order_by(db.Tag.first_name.asc())
|
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):
|
class UserSearchConfig(BaseSearchConfig):
|
||||||
''' Executes searches related to the users. '''
|
|
||||||
|
|
||||||
def create_filter_query(self):
|
def create_filter_query(self):
|
||||||
return db.session.query(db.User)
|
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):
|
def finalize_query(self, query):
|
||||||
return query.order_by(db.User.name.asc())
|
return query.order_by(db.User.name.asc())
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue