diff --git a/backend/app/controllers/posts_controller.rb b/backend/app/controllers/posts_controller.rb index 84a467f..3929863 100644 --- a/backend/app/controllers/posts_controller.rb +++ b/backend/app/controllers/posts_controller.rb @@ -37,8 +37,6 @@ class PostsController < ApplicationController offset = (page - 1) * limit - history_join_required = order[0] == 'updated_at' || updated_between.any?(&:present?) - q = filtered_posts(locale) .preload(:external_tags, :uploaded_user, :parents, :children, @@ -56,25 +54,9 @@ class PostsController < ApplicationController end q = q.where('posts.created_at >= ?', created_between[0]) if created_between[0] q = q.where('posts.created_at <= ?', created_between[1]) if created_between[1] + q = q.where('posts.updated_at >= ?', updated_between[0]) if updated_between[0] + q = q.where('posts.updated_at <= ?', updated_between[1]) if updated_between[1] count_scope = q - if history_join_required - history_times = HistoryAccess.visible(PostVersion.all) - .select('post_id, MAX(created_at) AS latest_at').group(:post_id) - q = q.joins("LEFT JOIN (#{ history_times.to_sql }) history_times " + - 'ON history_times.post_id = posts.id') - updated_at_all_sql = 'GREATEST(posts.updated_at, ' + - 'COALESCE(history_times.latest_at, posts.updated_at))' - end - if updated_between[0] - q = q.where("#{ updated_at_all_sql } >= ?", updated_between[0]) - end - if updated_between[1] - q = q.where("#{ updated_at_all_sql } <= ?", updated_between[1]) - end - count_scope = q if updated_between.any?(&:present?) - if history_join_required - q = q.select('posts.*', "#{ updated_at_all_sql } AS updated_at") - end sort_sql = case order[0] @@ -82,8 +64,6 @@ class PostsController < ApplicationController 'COALESCE(posts.original_created_before - INTERVAL 1 MINUTE,' + 'posts.original_created_from,' + 'posts.created_at) ' - when 'updated_at' - updated_at_all_sql else "posts.#{ order[0] }" end @@ -91,20 +71,11 @@ class PostsController < ApplicationController .limit(limit) .offset(offset) .to_a - latest_version_times = - if history_join_required - { } - else - HistoryAccess.visible(PostVersion.where(post_id: posts.map(&:id))) - .group(:post_id).maximum(:created_at) - end count_scope = count_scope.except(:select, :order) render json: { posts: posts.map { |post| - updated_at = [post.updated_at, latest_version_times[post.id]].compact.max - PostRepr.base(post, language_code: locale.language_code) - .merge('updated_at' => updated_at).tap do |json| + PostRepr.base(post, language_code: locale.language_code).tap do |json| json['thumbnail'] = if post.thumbnail.attached? rails_storage_proxy_url(post.thumbnail, only_path: false)