summaryrefslogtreecommitdiff
path: root/app/models/resource_weight_event.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-02 13:03:23 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-02 13:03:23 +0000
commita72a9af092c1bfcf9f8024d59c11cf222f07e1e7 (patch)
tree44b60265c1d476d026b2862d2c1244748f558d4f /app/models/resource_weight_event.rb
parentb085478c4c2bed74fdc6eb2c33bfc62e791baf03 (diff)
downloadgitlab-ce-a72a9af092c1bfcf9f8024d59c11cf222f07e1e7.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/resource_weight_event.rb')
-rw-r--r--app/models/resource_weight_event.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/app/models/resource_weight_event.rb b/app/models/resource_weight_event.rb
new file mode 100644
index 00000000000..ab288798aed
--- /dev/null
+++ b/app/models/resource_weight_event.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class ResourceWeightEvent < ApplicationRecord
+ include Gitlab::Utils::StrongMemoize
+
+ validates :user, presence: true
+ validates :issue, presence: true
+
+ belongs_to :user
+ belongs_to :issue
+
+ scope :by_issue, ->(issue) { where(issue_id: issue.id) }
+ scope :created_after, ->(time) { where('created_at > ?', time) }
+
+ def discussion_id(resource = nil)
+ strong_memoize(:discussion_id) do
+ Digest::SHA1.hexdigest(discussion_id_key.join("-"))
+ end
+ end
+
+ private
+
+ def discussion_id_key
+ [self.class.name, created_at, user_id]
+ end
+end