Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cs_comments_service
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
cs_comments_service
Commits
e55d8234
Commit
e55d8234
authored
Aug 09, 2016
by
wajeeha-khalid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MA-2678: replace use of 'updated_at' for 'read' state
parent
7cc9a131
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
47 additions
and
11 deletions
+47
-11
models/comment.rb
+1
-1
models/comment_thread.rb
+0
-1
presenters/thread_utils.rb
+2
-2
scripts/db/migrate-009-comment_thread-author-created_at-indexes.js
+1
-0
spec/api/comment_thread_spec.rb
+40
-4
spec/api/search_spec.rb
+1
-1
spec/spec_helper.rb
+2
-2
No files found.
models/comment.rb
View file @
e55d8234
...
@@ -25,6 +25,7 @@ class Comment < Content
...
@@ -25,6 +25,7 @@ class Comment < Content
index
({
author_id:
1
,
course_id:
1
})
index
({
author_id:
1
,
course_id:
1
})
index
({
_type:
1
,
comment_thread_id:
1
,
author_id:
1
,
updated_at:
1
})
index
({
_type:
1
,
comment_thread_id:
1
,
author_id:
1
,
updated_at:
1
})
index
({
comment_thread_id:
1
,
author_id:
1
,
created_at:
1
})
index_name
Content
::
ES_INDEX_NAME
index_name
Content
::
ES_INDEX_NAME
...
@@ -53,7 +54,6 @@ class Comment < Content
...
@@ -53,7 +54,6 @@ class Comment < Content
before_destroy
:destroy_children
before_destroy
:destroy_children
before_create
:set_thread_last_activity_at
before_create
:set_thread_last_activity_at
before_update
:set_thread_last_activity_at
before_save
:set_sk
before_save
:set_sk
def
self
.
hash_tree
(
nodes
)
def
self
.
hash_tree
(
nodes
)
...
...
models/comment_thread.rb
View file @
e55d8234
...
@@ -68,7 +68,6 @@ class CommentThread < Content
...
@@ -68,7 +68,6 @@ class CommentThread < Content
validates_presence_of
:author
,
autosave:
false
validates_presence_of
:author
,
autosave:
false
before_create
:set_last_activity_at
before_create
:set_last_activity_at
before_update
:set_last_activity_at
,
:unless
=>
lambda
{
closed_changed?
}
after_update
:clear_endorsements
after_update
:clear_endorsements
before_destroy
:destroy_subscriptions
before_destroy
:destroy_subscriptions
...
...
presenters/thread_utils.rb
View file @
e55d8234
...
@@ -27,11 +27,11 @@ module ThreadUtils
...
@@ -27,11 +27,11 @@ module ThreadUtils
threads
.
each
do
|
t
|
threads
.
each
do
|
t
|
thread_key
=
t
.
_id
.
to_s
thread_key
=
t
.
_id
.
to_s
if
read_dates
.
has_key?
thread_key
if
read_dates
.
has_key?
thread_key
is_read
=
read_dates
[
thread_key
]
>=
t
.
updated
_at
is_read
=
read_dates
[
thread_key
]
>=
t
.
last_activity
_at
unread_comment_count
=
Comment
.
collection
.
find
(
unread_comment_count
=
Comment
.
collection
.
find
(
:comment_thread_id
=>
t
.
_id
,
:comment_thread_id
=>
t
.
_id
,
:author_id
=>
{
"$ne"
=>
user
.
id
},
:author_id
=>
{
"$ne"
=>
user
.
id
},
:
updated_at
=>
{
"$gte"
=>
read_dates
[
thread_key
]},
:
created_at
=>
{
"$gte"
=>
read_dates
[
thread_key
]}
).
count
).
count
read_states
[
thread_key
]
=
[
is_read
,
unread_comment_count
]
read_states
[
thread_key
]
=
[
is_read
,
unread_comment_count
]
end
end
...
...
scripts/db/migrate-009-comment_thread-author-created_at-indexes.js
0 → 100644
View file @
e55d8234
db
.
contents
.
ensureIndex
({
comment_thread_id
:
1
,
author_id
:
1
,
created_at
:
1
},
{
background
:
true
})
spec/api/comment_thread_spec.rb
View file @
e55d8234
...
@@ -211,7 +211,7 @@ describe "app" do
...
@@ -211,7 +211,7 @@ describe "app" do
rs
.
each_with_index
{
|
result
,
i
|
rs
.
each_with_index
{
|
result
,
i
|
check_thread_result_json
(
user
,
@threads
[
"t
#{
i
+
1
}
"
],
result
)
check_thread_result_json
(
user
,
@threads
[
"t
#{
i
+
1
}
"
],
result
)
}
}
rs
[
0
][
"read"
].
should
==
false
# no unread comments, but the thread itself was updated
rs
[
0
][
"read"
].
should
==
true
rs
[
0
][
"unread_comments_count"
].
should
==
0
rs
[
0
][
"unread_comments_count"
].
should
==
0
rs
[
1
][
"read"
].
should
==
false
rs
[
1
][
"read"
].
should
==
false
rs
[
1
][
"unread_comments_count"
].
should
==
5
rs
[
1
][
"unread_comments_count"
].
should
==
5
...
@@ -258,19 +258,55 @@ describe "app" do
...
@@ -258,19 +258,55 @@ describe "app" do
expected_order
=
@default_order
expected_order
=
@default_order
actual_order
.
should
==
expected_order
actual_order
.
should
==
expected_order
end
end
it
"sorts using last activity / descending"
do
it
"sort unchanged using last activity / descending when thread is updated"
do
t5
=
@threads
[
"t5"
]
t5
.
update
(
body:
"changed!"
)
t5
.
save!
actual_order
=
thread_result_order
(
"activity"
,
"desc"
)
expected_order
=
@default_order
actual_order
.
should
==
expected_order
end
it
"sort unchanged using last activity / ascending when thread is updated"
do
t5
=
@threads
[
"t5"
]
t5
.
update
(
body:
"changed!"
)
t5
.
save!
actual_order
=
thread_result_order
(
"activity"
,
"asc"
)
expected_order
=
@default_order
.
reverse
actual_order
.
should
==
expected_order
end
it
"sort unchanged using last activity / descending when comment is updated"
do
t5c
=
@threads
[
"t5"
].
comments
.
first
t5c
=
@threads
[
"t5"
].
comments
.
first
t5c
.
update
(
body:
"changed!"
)
t5c
.
update
(
body:
"changed!"
)
t5c
.
save!
t5c
.
save!
actual_order
=
thread_result_order
(
"activity"
,
"desc"
)
actual_order
=
thread_result_order
(
"activity"
,
"desc"
)
expected_order
=
move_to_front
(
@default_order
,
"t5"
)
expected_order
=
@default_order
actual_order
.
should
==
expected_order
actual_order
.
should
==
expected_order
end
end
it
"sort
s using last activity / ascending
"
do
it
"sort
unchanged using last activity / ascending when comment is updated
"
do
t5c
=
@threads
[
"t5"
].
comments
.
first
t5c
=
@threads
[
"t5"
].
comments
.
first
t5c
.
update
(
body:
"changed!"
)
t5c
.
update
(
body:
"changed!"
)
t5c
.
save!
t5c
.
save!
actual_order
=
thread_result_order
(
"activity"
,
"asc"
)
actual_order
=
thread_result_order
(
"activity"
,
"asc"
)
expected_order
=
@default_order
.
reverse
actual_order
.
should
==
expected_order
end
it
"sorts using last activity / descending when response is created"
do
t5
=
@threads
[
"t5"
]
comment
=
t5
.
comments
.
new
(
body:
"this problem is so easy"
,
course_id:
"1"
)
comment
.
author
=
User
.
first
comment
.
save!
actual_order
=
thread_result_order
(
"activity"
,
"desc"
)
expected_order
=
move_to_front
(
@default_order
,
"t5"
)
actual_order
.
should
==
expected_order
end
it
"sorts using last activity / ascending when response is created"
do
t5
=
@threads
[
"t5"
]
comment
=
t5
.
comments
.
new
(
body:
"this problem is so easy"
,
course_id:
"1"
)
comment
.
author
=
User
.
first
comment
.
save!
actual_order
=
thread_result_order
(
"activity"
,
"asc"
)
expected_order
=
move_to_end
(
@default_order
.
reverse
,
"t5"
)
expected_order
=
move_to_end
(
@default_order
.
reverse
,
"t5"
)
actual_order
.
should
==
expected_order
actual_order
.
should
==
expected_order
end
end
...
...
spec/api/search_spec.rb
View file @
e55d8234
...
@@ -175,7 +175,7 @@ describe "app" do
...
@@ -175,7 +175,7 @@ describe "app" do
end
end
it
"by activity"
do
it
"by activity"
do
asc_order
=
[
0
,
2
,
5
,
1
,
3
,
4
]
asc_order
=
[
0
,
1
,
2
,
3
,
4
,
5
]
check_sort
(
"activity"
,
"asc"
,
asc_order
)
check_sort
(
"activity"
,
"asc"
,
asc_order
)
check_sort
(
"activity"
,
"desc"
,
asc_order
.
reverse
)
check_sort
(
"activity"
,
"desc"
,
asc_order
.
reverse
)
end
end
...
...
spec/spec_helper.rb
View file @
e55d8234
...
@@ -214,11 +214,11 @@ def check_thread_result(user, thread, hash, is_json=false)
...
@@ -214,11 +214,11 @@ def check_thread_result(user, thread, hash, is_json=false)
read_date
=
read_states
.
first
.
last_read_times
[
thread
.
id
.
to_s
]
read_date
=
read_states
.
first
.
last_read_times
[
thread
.
id
.
to_s
]
if
read_date
if
read_date
thread
.
comments
.
each
do
|
c
|
thread
.
comments
.
each
do
|
c
|
if
c
.
upd
ated_at
<
read_date
if
c
.
cre
ated_at
<
read_date
expected_unread_cnt
-=
1
expected_unread_cnt
-=
1
end
end
end
end
hash
[
"read"
].
should
==
(
read_date
>=
thread
.
updated
_at
)
hash
[
"read"
].
should
==
(
read_date
>=
thread
.
last_activity
_at
)
else
else
hash
[
"read"
].
should
==
false
hash
[
"read"
].
should
==
false
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment