summaryrefslogtreecommitdiff
path: root/app/models/discussion.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/discussion.rb')
-rw-r--r--app/models/discussion.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/app/models/discussion.rb b/app/models/discussion.rb
index 70aa02063cc..076d8cc280c 100644
--- a/app/models/discussion.rb
+++ b/app/models/discussion.rb
@@ -7,6 +7,9 @@ class Discussion
include GlobalID::Identification
include ResolvableDiscussion
+ # Bump this if we need to refresh the cached versions of discussions
+ CACHE_VERSION = 1
+
attr_reader :notes, :context_noteable
delegate :created_at,
@@ -158,4 +161,19 @@ class Discussion
def reply_attributes
first_note.slice(:type, :noteable_type, :noteable_id, :commit_id, :discussion_id)
end
+
+ def cache_key
+ # Need this so cache will be invalidated when note within a discussion
+ # has been deleted.
+ notes_sha = Digest::SHA1.hexdigest(notes.map(&:id).join(':'))
+
+ [
+ CACHE_VERSION,
+ notes.last.latest_cached_markdown_version,
+ id,
+ notes_sha,
+ notes.max_by(&:updated_at).updated_at,
+ resolved_at
+ ].join(':')
+ end
end