summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/event.rb9
-rw-r--r--app/models/event_collection.rb9
-rw-r--r--app/models/issue.rb2
-rw-r--r--app/models/merge_request.rb2
-rw-r--r--app/models/release.rb20
-rw-r--r--app/models/releases/evidence.rb (renamed from app/models/evidence.rb)6
6 files changed, 29 insertions, 19 deletions
diff --git a/app/models/event.rb b/app/models/event.rb
index c4ca5389fdf..447ab753421 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -36,6 +36,8 @@ class Event < ApplicationRecord
expired: EXPIRED
).freeze
+ WIKI_ACTIONS = [CREATED, UPDATED, DESTROYED].freeze
+
TARGET_TYPES = HashWithIndifferentAccess.new(
issue: Issue,
milestone: Milestone,
@@ -81,7 +83,10 @@ class Event < ApplicationRecord
scope :recent, -> { reorder(id: :desc) }
scope :code_push, -> { where(action: PUSHED) }
scope :merged, -> { where(action: MERGED) }
- scope :for_wiki_page, -> { where(target_type: WikiPage::Meta.name) }
+ scope :for_wiki_page, -> { where(target_type: 'WikiPage::Meta') }
+
+ # Needed to implement feature flag: can be removed when feature flag is removed
+ scope :not_wiki_page, -> { where('target_type IS NULL or target_type <> ?', 'WikiPage::Meta') }
scope :with_associations, -> do
# We're using preload for "push_event_payload" as otherwise the association
@@ -229,7 +234,7 @@ class Event < ApplicationRecord
end
def wiki_page?
- target_type == WikiPage::Meta.name
+ target_type == 'WikiPage::Meta'
end
def milestone
diff --git a/app/models/event_collection.rb b/app/models/event_collection.rb
index 4768506b8fa..4c178e27b75 100644
--- a/app/models/event_collection.rb
+++ b/app/models/event_collection.rb
@@ -33,16 +33,23 @@ class EventCollection
project_events
end
+ relation = apply_feature_flags(relation)
relation = paginate_events(relation)
relation.with_associations.to_a
end
def all_project_events
- Event.from_union([project_events]).recent
+ apply_feature_flags(Event.from_union([project_events]).recent)
end
private
+ def apply_feature_flags(events)
+ return events if ::Feature.enabled?(:wiki_events)
+
+ events.not_wiki_page
+ end
+
def project_events
relation_with_join_lateral('project_id', projects)
end
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 3d389013985..bdcebb4b942 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -78,8 +78,6 @@ class Issue < ApplicationRecord
scope :counts_by_state, -> { reorder(nil).group(:state_id).count }
- ignore_column :state, remove_with: '12.10', remove_after: '2020-03-22'
-
after_commit :expire_etag_cache, unless: :importing?
after_save :ensure_metrics, unless: :importing?
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index bb7afc49cd8..7934b0f8f59 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -261,8 +261,6 @@ class MergeRequest < ApplicationRecord
includes(:metrics)
end
- ignore_column :state, remove_with: '12.10', remove_after: '2020-03-22'
-
after_save :keep_around_commit, unless: :importing?
alias_attribute :project, :target_project
diff --git a/app/models/release.rb b/app/models/release.rb
index 45c2a56d764..403087a2cad 100644
--- a/app/models/release.rb
+++ b/app/models/release.rb
@@ -16,7 +16,7 @@ class Release < ApplicationRecord
has_many :milestone_releases
has_many :milestones, through: :milestone_releases
- has_one :evidence
+ has_many :evidences, inverse_of: :release, class_name: 'Releases::Evidence'
default_value_for :released_at, allows_nil: false do
Time.zone.now
@@ -28,7 +28,7 @@ class Release < ApplicationRecord
validates_associated :milestone_releases, message: -> (_, obj) { obj[:value].map(&:errors).map(&:full_messages).join(",") }
scope :sorted, -> { order(released_at: :desc) }
- scope :preloaded, -> { includes(project: :namespace) }
+ scope :preloaded, -> { includes(:evidences, :milestones, project: [:project_feature, :route, { namespace: :route }]) }
scope :with_project_and_namespace, -> { includes(project: :namespace) }
scope :recent, -> { sorted.limit(MAX_NUMBER_TO_DISPLAY) }
@@ -66,27 +66,27 @@ class Release < ApplicationRecord
end
def upcoming_release?
- released_at.present? && released_at > Time.zone.now
+ released_at.present? && released_at.to_i > Time.zone.now.to_i
end
def historical_release?
- released_at.present? && released_at < created_at
+ released_at.present? && released_at.to_i < created_at.to_i
end
def name
self.read_attribute(:name) || tag
end
- def evidence_sha
- evidence&.summary_sha
+ def milestone_titles
+ self.milestones.map {|m| m.title }.sort.join(", ")
end
- def evidence_summary
- evidence&.summary || {}
+ def evidence_sha
+ evidences.first&.summary_sha
end
- def milestone_titles
- self.milestones.map {|m| m.title }.sort.join(", ")
+ def evidence_summary
+ evidences.first&.summary || {}
end
private
diff --git a/app/models/evidence.rb b/app/models/releases/evidence.rb
index 55149ab0dfa..1aac7e33e41 100644
--- a/app/models/evidence.rb
+++ b/app/models/releases/evidence.rb
@@ -1,15 +1,17 @@
# frozen_string_literal: true
-class Evidence < ApplicationRecord
+class Releases::Evidence < ApplicationRecord
include ShaAttribute
+ include Presentable
- belongs_to :release
+ belongs_to :release, inverse_of: :evidences
before_validation :generate_summary_and_sha
default_scope { order(created_at: :asc) }
sha_attribute :summary_sha
+ alias_attribute :collected_at, :created_at
def milestones
@milestones ||= release.milestones.includes(:issues)