From 371a0494b7f2a59719873521b77e76c34dab3e47 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Wed, 7 Feb 2018 11:44:38 +0100 Subject: [PATCH] Fixed issue #1769 - Ticket shown multiple times in overview. --- app/models/ticket.rb | 8 ++++---- app/models/ticket/overviews.rb | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 4883e8764..e290978b2 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -424,14 +424,14 @@ get count of tickets and tickets which match on selector ActiveRecord::Base.transaction(requires_new: true) do begin if !current_user - ticket_count = Ticket.where(query, *bind_params).joins(tables).count - tickets = Ticket.where(query, *bind_params).joins(tables).limit(limit) + ticket_count = Ticket.where(query, *bind_params).joins(tables).group('tickets.id').count + tickets = Ticket.where(query, *bind_params).joins(tables).group('tickets.id').limit(limit) return [ticket_count, tickets] end access_condition = Ticket.access_condition(current_user, access) - ticket_count = Ticket.where(access_condition).where(query, *bind_params).joins(tables).count - tickets = Ticket.where(access_condition).where(query, *bind_params).joins(tables).limit(limit) + ticket_count = Ticket.where(access_condition).where(query, *bind_params).joins(tables).group('tickets.id').count + tickets = Ticket.where(access_condition).where(query, *bind_params).joins(tables).group('tickets.id').limit(limit) return [ticket_count, tickets] rescue ActiveRecord::StatementInvalid => e diff --git a/app/models/ticket/overviews.rb b/app/models/ticket/overviews.rb index 393490f19..354511361 100644 --- a/app/models/ticket/overviews.rb +++ b/app/models/ticket/overviews.rb @@ -113,10 +113,11 @@ returns end end - ticket_result = Ticket.select('id, updated_at') + ticket_result = Ticket.select('tickets.id, tickets.updated_at') .where(access_condition) .where(query_condition, *bind_condition) .joins(tables) + .group('tickets.id') .order(order_by) .limit(1000) .pluck(:id, :updated_at) @@ -129,7 +130,7 @@ returns } tickets.push ticket_item end - count = Ticket.where(access_condition).where(query_condition, *bind_condition).joins(tables).count() + count = Ticket.where(access_condition).where(query_condition, *bind_condition).joins(tables).group('tickets.id').count() item = { overview: { name: overview.name,