debian-mirror-gitlab/app/models/issue/metrics.rb

34 lines
1 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2019-07-07 11:18:12 +05:30
class Issue::Metrics < ApplicationRecord
2016-09-29 09:46:39 +05:30
belongs_to :issue
2020-01-01 13:55:28 +05:30
scope :for_issues, ->(issues) { where(issue: issues) }
scope :with_first_mention_not_earlier_than, -> (timestamp) {
where(first_mentioned_in_commit_at: nil)
.or(where(arel_table['first_mentioned_in_commit_at'].gteq(timestamp)))
}
2016-09-29 09:46:39 +05:30
def record!
if issue.milestone_id.present? && self.first_associated_with_milestone_at.blank?
2020-06-23 00:09:42 +05:30
self.first_associated_with_milestone_at = Time.current
2016-09-29 09:46:39 +05:30
end
if issue_assigned_to_list_label? && self.first_added_to_board_at.blank?
2020-06-23 00:09:42 +05:30
self.first_added_to_board_at = Time.current
2016-09-29 09:46:39 +05:30
end
self.save
end
private
def issue_assigned_to_list_label?
2021-06-08 01:23:25 +05:30
# Avoid another DB lookup when issue.labels are empty by adding a guard clause here
# We can't use issue.labels.empty? because that will cause a `Label Exists?` DB lookup
return false if issue.labels.length == 0 # rubocop:disable Style/ZeroLengthPredicate
issue.labels.includes(:lists).any? { |label| label.lists.present? }
2016-09-29 09:46:39 +05:30
end
end