Slightly improve Statistics Controller performance
This commit is contained in:
@ -43,9 +43,7 @@ module StatisticsHelper
|
||||
{
|
||||
key: 'currently_active',
|
||||
name: t('statistics.entries.users.currently_active'),
|
||||
data: ExternalUser.joins(:submissions)
|
||||
.where(['submissions.created_at >= ?', DateTime.now - 5.minutes])
|
||||
.distinct('external_users.id').count,
|
||||
data: Submission.where(created_at: 5.minutes.ago.., user_type: ExternalUser.name).distinct.count(:user_id),
|
||||
url: statistics_graphs_path,
|
||||
},
|
||||
]
|
||||
@ -81,6 +79,7 @@ module StatisticsHelper
|
||||
{
|
||||
key: 'container_requests_per_minute',
|
||||
name: t('statistics.entries.exercises.container_requests_per_minute'),
|
||||
# This query is actually quite expensive since we do not have an index on the created_at column.
|
||||
data: (Testrun.where(created_at: DateTime.now - 1.hour..).count.to_f / 60).round(2),
|
||||
unit: '/min',
|
||||
},
|
||||
|
@ -17,7 +17,7 @@ class RequestForComment < ApplicationRecord
|
||||
has_many :subscriptions, dependent: :destroy
|
||||
|
||||
scope :unsolved, -> { where(solved: [false, nil]) }
|
||||
scope :in_range, ->(from, to) { where(created_at: from..to) }
|
||||
scope :in_range, ->(from, to) { from == DateTime.new(0) && to > 5.seconds.ago ? all : where(created_at: from..to) }
|
||||
scope :with_comments, -> { select {|rfc| rfc.comments.any? } }
|
||||
|
||||
# after_save :trigger_rfc_action_cable
|
||||
|
Reference in New Issue
Block a user