From 7e7b40f4125096aac8974f0051354d85e41b2a17 Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Sun, 14 Mar 2021 16:40:01 +0100 Subject: [PATCH] Choose a random package for the main page to ask for screenshots --- app/controllers/welcome_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 72536eb..4310eee 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -6,7 +6,11 @@ class WelcomeController < ApplicationController @package_count = Package.count - @most_wanted_package = Package.without_screenshots.order(visits: :desc).first + # Get up 100 screenshots where the packages have the most visits + query = Package.without_screenshots.order(visits: :desc) + count = query.count + random_offset = rand( [100, count].min ) + @most_wanted_package = query.offset(random_offset).first end def about