Skip to content

Commit dc5aef4

Browse files
authored
Merge pull request #1830 from codidact/0valt/caching
Further caching improvement
2 parents 7c3c26e + d6d2216 commit dc5aef4

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

app/models/comment.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ class Comment < ApplicationRecord
1919

2020
validate :content_length
2121

22+
# Gets last activity date and time on the comment
23+
# @return [DateTime] last activity date and time
24+
def last_activity_at
25+
[created_at, updated_at].compact.max
26+
end
27+
2228
def root
2329
# If parent_question is nil, the comment is already on a question, so we can just return post.
2430
parent_question || post

app/models/comment_thread.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def can_access?(user)
5252
# Gets last activity date and time on the thread
5353
# @return [DateTime] last activity date and time
5454
def last_activity_at
55-
[created_at, locked_at, updated_at].compact.max
55+
last_comment_activity_at = comments.map(&:last_activity_at).max
56+
[created_at, locked_at, updated_at, last_comment_activity_at].compact.max
5657
end
5758

5859
# Gets a list of user IDs who should be pingable in the thread.

test/fixtures/comments.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ one:
44
content: ABCDEF GHIJKL MNOPQR
55
community: sample
66
comment_thread: normal
7+
created_at: 2020-01-01T00:00:00.000000Z
8+
updated_at: 2021-01-01T00:00:00.000000Z
79

810
two:
911
user: standard_user
1012
post: question_two
1113
content: ABCDEF GHIJKL MNOPQR
1214
community: sample
1315
comment_thread: normal_two
16+
created_at: 2020-01-01T00:00:00.000000Z
17+
updated_at: 2021-01-01T00:00:00.000000Z
1418

1519
deleted:
1620
user: standard_user
@@ -19,38 +23,50 @@ deleted:
1923
deleted: true
2024
community: sample
2125
comment_thread: normal
26+
created_at: 2020-01-01T00:00:00.000000Z
27+
updated_at: 2021-01-01T00:00:00.000000Z
2228

2329
deleted_thread:
2430
user: standard_user
2531
post: question_one
2632
content: ABCDEF GHIJKL MNOPQR
2733
community: sample
2834
comment_thread: deleted
35+
created_at: 2020-01-01T00:00:00.000000Z
36+
updated_at: 2021-01-01T00:00:00.000000Z
2937

3038
locked_thread:
3139
user: standard_user
3240
post: question_one
3341
content: ABCDEF GHIJKL MNOPQR
3442
community: sample
3543
comment_thread: locked
44+
created_at: 2020-01-01T00:00:00.000000Z
45+
updated_at: 2021-01-01T00:00:00.000000Z
3646

3747
archived_thread:
3848
user: standard_user
3949
post: question_one
4050
content: ABCDEF GHIJKL MNOPQR
4151
community: sample
4252
comment_thread: archived
53+
created_at: 2020-01-01T00:00:00.000000Z
54+
updated_at: 2021-01-01T00:00:00.000000Z
4355

4456
on_answer:
4557
user: standard_user
4658
post: answer_one
4759
content: ABCDEF GHIJKL MNOPQR
4860
community: sample
4961
comment_thread: on_answer
62+
created_at: 2020-01-01T00:00:00.000000Z
63+
updated_at: 2021-01-01T00:00:00.000000Z
5064

5165
new_user_on_own_post:
5266
user: basic_user
5367
post: new_user_question
5468
content: ABCDEF GHIJKL MNOPQR
5569
community: sample
5670
comment_thread: new_user_on_own_post
71+
created_at: 2020-01-01T00:00:00.000000Z
72+
updated_at: 2021-01-01T00:00:00.000000Z

0 commit comments

Comments
 (0)