diff --git a/app/controllers/explore_controller.rb b/app/controllers/explore_controller.rb index 5cc3e95f..4b4d725f 100644 --- a/app/controllers/explore_controller.rb +++ b/app/controllers/explore_controller.rb @@ -2,17 +2,9 @@ class ExploreController < ApplicationController VARIANTS = %i[devlog fire certified ship].freeze def index - # Get non-tutorial devlog IDs, filtering out deleted ones for regular users - devlog_scope = Post::Devlog.where(tutorial: false) - devlog_scope = devlog_scope.with_deleted if current_user&.can_see_deleted_devlogs? - - non_tutorial_devlog_ids = devlog_scope.select(:id) - - scope = Post.includes(:user, :project, postable: { attachments_attachments: :blob, likes: [] }) - .where(postable_type: "Post::Devlog") - .where("posts.postable_id::bigint IN (?)", non_tutorial_devlog_ids) - .where.not(user_id: current_user&.id) - .order(created_at: :desc) + scope = Post::Devlog.includes(:project, :user, attachments_attachments: :blob) + .where(tutorial: false) + .where.not(user: current_user&.id) @pagy, @devlogs = pagy(scope) @@ -39,9 +31,9 @@ def index def gallery scope = Project.includes(banner_attachment: :blob) - .where(tutorial: false) - .where.not(id: current_user&.projects&.pluck(:id) || []) - .order(created_at: :desc) + .where(tutorial: false) + .excluding_member(current_user) + .order(created_at: :desc) @pagy, @projects = pagy(scope) diff --git a/app/models/project.rb b/app/models/project.rb index 47550986..2b6034d0 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -47,6 +47,9 @@ class Project < ApplicationRecord "Minecraft Mods", "Hardware", "Android App", "iOS App", "Other" ].freeze + scope :excluding_member, ->(user) { + user ? where.not(id: user.projects) : all + } scope :fire, -> { where.not(marked_fire_at: nil) } belongs_to :marked_fire_by, class_name: "User", optional: true