SQL optimisation rolled back. It lead to access problems.

This commit is contained in:
Christoph Haas 2021-03-01 02:07:55 +01:00
parent 7227f769c0
commit 2b24083653
5 changed files with 15 additions and 19 deletions

View file

@ -288,9 +288,8 @@ class PackagesController < ApplicationController
# Return packages matching the criteria given by parameters
def query_packages
# Eager load the screenshots to avoid N+1 queries to check Screenshot.accessible_by later
packages = Package.includes(:screenshots).order(visits: :desc)
packages = Package.order(visits: :desc)
# text search
if params[:search].present?
logger.debug "Searching for #{params[:search]}"
@ -300,15 +299,11 @@ class PackagesController < ApplicationController
case params[:show]
when 'with'
# Enrich the result with the screenshots readable by the current user (CanCanCan)
packages = packages.where(screenshots: Screenshot.accessible_by(current_ability, :view))
packages = packages.with_screenshots
logger.debug 'Limiting packages to those with screenshots'
when 'without'
packages = packages.without_screenshots
logger.debug 'Limiting packages to those without screenshots'
else
packages = packages.where(screenshots: Screenshot.accessible_by(current_ability, :view)).or(
packages.without_screenshots)
end
return packages