server/posts: add relation-count token

This commit is contained in:
rr-
2016-06-13 20:08:39 +02:00
parent c508d37d54
commit 6b68c77e17
4 changed files with 17 additions and 0 deletions

View File

@ -187,3 +187,8 @@ class Post(Base):
select([func.count(PostNote.post_id)]) \
.where(PostNote.post_id == post_id) \
.correlate_except(PostNote))
relation_count = column_property(
select([func.count(PostRelation.child_id)]) \
.where(PostRelation.parent_id == post_id) \
.correlate_except(PostRelation))

View File

@ -153,6 +153,7 @@ class PostSearchConfig(BaseSearchConfig):
'comment-count': search_util.create_num_filter(db.Post.comment_count),
'fav-count': search_util.create_num_filter(db.Post.favorite_count),
'note-count': search_util.create_num_filter(db.Post.note_count),
'relation-count': search_util.create_num_filter(db.Post.relation_count),
'feature-count': search_util.create_num_filter(db.Post.feature_count),
'type': search_util.create_str_filter(db.Post.type, _type_transformer),
'file-size': search_util.create_num_filter(db.Post.file_size),
@ -186,6 +187,7 @@ class PostSearchConfig(BaseSearchConfig):
'comment-count': (db.Post.comment_count, self.SORT_DESC),
'fav-count': (db.Post.favorite_count, self.SORT_DESC),
'note-count': (db.Post.note_count, self.SORT_DESC),
'relation-count': (db.Post.relation_count, self.SORT_DESC),
'feature-count': (db.Post.feature_count, self.SORT_DESC),
'file-size': (db.Post.file_size, self.SORT_DESC),
('image-width', 'width'): (db.Post.canvas_width, self.SORT_DESC),