From ab5e32459d08b20f1a277e46c63e433c3b42b53b Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Thu, 24 Aug 2023 15:03:49 -0400 Subject: [PATCH] better sorting --- app/controllers/api/v1/cases_controller.rb | 6 +++++- app/controllers/home_controller.rb | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/cases_controller.rb b/app/controllers/api/v1/cases_controller.rb index 28835fab3..21ddbf4db 100644 --- a/app/controllers/api/v1/cases_controller.rb +++ b/app/controllers/api/v1/cases_controller.rb @@ -36,7 +36,11 @@ def index elsif sort_by current_user.cases_involved_with.preload( :tries).not_archived.order(sort_by) else - current_user.cases_involved_with.preload(:tries, :teams, :cases_teams).not_archived + current_user.cases_involved_with.preload(:tries, :teams, + :cases_teams) + .not_archived + .left_outer_joins(:metadata) + .order(Arel.sql('`case_metadata`.`last_viewed_at` DESC, `cases`.`updated_at` DESC')) end end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 2b309a82a..0b86577c5 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -2,9 +2,12 @@ class HomeController < ApplicationController # rubocop:disable Metrics/AbcSize + # rubocop:disable Metrics/MethodLength def show # @cases = @current_user.cases.not_archived.includes([ :scores ]) @cases = @current_user.cases.not_archived + .left_outer_joins(:metadata) + .order(Arel.sql('`case_metadata`.`last_viewed_at` DESC, `cases`.`updated_at` DESC')) # copied from dropdown_contoller.rb @most_recent_cases = lookup_most_recent_cases @@ -26,6 +29,7 @@ def show @grouped_cases = @grouped_cases.select { |_key, value| value.count > 1 } end # rubocop:enable Metrics/AbcSize + # rubocop:enable Metrics/MethodLength private