From 3acb66d7986816b325f3b46d9a5af7e8b4676981 Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Tue, 30 Dec 2025 18:18:29 -0500 Subject: [PATCH 1/2] Simplify explore/devlog lookup --- app/controllers/explore_controller.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/app/controllers/explore_controller.rb b/app/controllers/explore_controller.rb index 5cc3e95f..8c7e6f4c 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) From 30e7cfac5c7ab4251fb29dde1645910b9cddca09 Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Tue, 30 Dec 2025 18:18:42 -0500 Subject: [PATCH 2/2] Simplify explore/project lookup --- app/controllers/explore_controller.rb | 6 +++--- app/models/project.rb | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/explore_controller.rb b/app/controllers/explore_controller.rb index 8c7e6f4c..4b4d725f 100644 --- a/app/controllers/explore_controller.rb +++ b/app/controllers/explore_controller.rb @@ -31,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