posts: show length of videos and animations in thumbnails.
Show the length of videos and animated posts in the thumbnail. The length is shown the top left corner in MM:SS format. This replaces the play button icon. Show a speaker icon instead of a music note icon for posts with sound. Doing this requires doing `.includes(:media_asset)` in a bunch of places to avoid N+1 queries when we access the post's duration.
This commit is contained in:
@@ -66,7 +66,7 @@ class IqdbClient
|
||||
def process_results(matches, low_similarity, high_similarity)
|
||||
matches = matches.select { |result| result["score"] >= low_similarity }
|
||||
post_ids = matches.map { |match| match["post_id"] }
|
||||
posts = Post.where(id: post_ids).group_by(&:id).transform_values(&:first)
|
||||
posts = Post.includes(:media_asset).where(id: post_ids).group_by(&:id).transform_values(&:first)
|
||||
|
||||
matches = matches.map do |match|
|
||||
post = posts.fetch(match["post_id"], nil)
|
||||
|
||||
@@ -489,10 +489,10 @@ class PostQueryBuilder
|
||||
relation
|
||||
end
|
||||
|
||||
def build
|
||||
def build(includes: nil)
|
||||
validate!
|
||||
|
||||
relation = Post.all
|
||||
relation = Post.includes(includes)
|
||||
relation = add_joins(relation)
|
||||
relation = metatags_match(metatags, relation)
|
||||
relation = tags_match(tags, relation)
|
||||
@@ -514,8 +514,8 @@ class PostQueryBuilder
|
||||
relation
|
||||
end
|
||||
|
||||
def paginated_posts(page, small_search_threshold: Danbooru.config.small_search_threshold.to_i, **options)
|
||||
posts = build.paginate(page, **options)
|
||||
def paginated_posts(page, small_search_threshold: Danbooru.config.small_search_threshold.to_i, includes: nil, **options)
|
||||
posts = build(includes: includes).paginate(page, **options)
|
||||
posts = optimize_search(posts, small_search_threshold)
|
||||
posts.load
|
||||
end
|
||||
|
||||
@@ -107,7 +107,7 @@ module PostSets
|
||||
if is_random?
|
||||
get_random_posts.paginate(page, search_count: false, limit: per_page, max_limit: max_per_page).load
|
||||
else
|
||||
normalized_query.paginated_posts(page, count: post_count, search_count: !post_count.nil?, limit: per_page, max_limit: max_per_page).load
|
||||
normalized_query.paginated_posts(page, includes: :media_asset, count: post_count, search_count: !post_count.nil?, limit: per_page, max_limit: max_per_page).load
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -59,7 +59,7 @@ module RecommenderService
|
||||
# Process a set of recommendations to filter out posts the user uploaded
|
||||
# themselves, or has already favorited, or that don't match a tag search.
|
||||
def process_recs(recs, post: nil, uploader: nil, favoriter: nil, tags: nil)
|
||||
posts = Post.where(id: recs.map(&:first))
|
||||
posts = Post.includes(:media_asset).where(id: recs.map(&:first))
|
||||
posts = posts.where.not(id: post.id) if post
|
||||
posts = posts.where.not(uploader_id: uploader.id) if uploader
|
||||
posts = posts.where.not(id: favoriter.favorites.select(:post_id)) if favoriter
|
||||
|
||||
Reference in New Issue
Block a user