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
346c65ee
Commit
346c65ee
authored
Mar 17, 2017
by
Joel Barciauskas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove trace_execution_scoped blocks
parent
1258b84c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
108 deletions
+98
-108
api/search.rb
+30
-32
api/users.rb
+5
-7
lib/helpers.rb
+11
-15
models/user.rb
+52
-54
No files found.
api/search.rb
View file @
346c65ee
...
@@ -20,42 +20,40 @@ def get_thread_ids(context, group_ids, local_params, search_text)
...
@@ -20,42 +20,40 @@ def get_thread_ids(context, group_ids, local_params, search_text)
)
)
end
end
self
.
class
.
trace_execution_scoped
([
'Custom/get_search_threads/es_search'
])
do
body
=
{
body
=
{
size:
CommentService
.
config
[
'max_deep_search_comment_count'
].
to_i
,
size:
CommentService
.
config
[
'max_deep_search_comment_count'
].
to_i
,
sort:
[
sort:
[
{
updated_at: :desc
}
{
updated_at: :desc
}
],
],
query:
{
query:
{
multi_match:
{
multi_match:
{
query:
search_text
,
query:
search_text
,
fields:
[
:title
,
:body
],
fields:
[
:title
,
:body
],
operator: :AND
operator: :AND
},
},
filtered:
{
filtered:
{
filter:
{
filter:
{
and:
filters
and:
filters
}
}
}
}
}
}
}
}
response
=
Elasticsearch
::
Model
.
client
.
search
(
index:
Content
::
ES_INDEX_NAME
,
body:
body
)
response
=
Elasticsearch
::
Model
.
client
.
search
(
index:
Content
::
ES_INDEX_NAME
,
body:
body
)
thread_ids
=
Set
.
new
thread_ids
=
Set
.
new
response
[
'hits'
][
'hits'
].
each
do
|
hit
|
response
[
'hits'
][
'hits'
].
each
do
|
hit
|
case
hit
[
'_type'
]
case
hit
[
'_type'
]
when
CommentThread
.
document_type
when
CommentThread
.
document_type
thread_ids
.
add
(
hit
[
'_id'
])
thread_ids
.
add
(
hit
[
'_id'
])
when
Comment
.
document_type
when
Comment
.
document_type
thread_ids
.
add
(
hit
[
'_source'
][
'comment_thread_id'
])
thread_ids
.
add
(
hit
[
'_source'
][
'comment_thread_id'
])
else
else
# There shouldn't be any other document types. Nevertheless, ignore them, if they are present.
# There shouldn't be any other document types. Nevertheless, ignore them, if they are present.
next
next
end
end
end
thread_ids
end
end
thread_ids
end
end
def
get_suggested_text
(
search_text
)
def
get_suggested_text
(
search_text
)
...
...
api/users.rb
View file @
346c65ee
...
@@ -54,13 +54,11 @@ get "#{APIPREFIX}/users/:user_id/active_threads" do |user_id|
...
@@ -54,13 +54,11 @@ get "#{APIPREFIX}/users/:user_id/active_threads" do |user_id|
collection
=
presenter
.
to_hash
collection
=
presenter
.
to_hash
json_output
=
nil
json_output
=
nil
self
.
class
.
trace_execution_scoped
([
'Custom/get_user_active_threads/json_serialize'
])
do
json_output
=
{
json_output
=
{
collection:
collection
,
collection:
collection
,
num_pages:
num_pages
,
num_pages:
num_pages
,
page:
page
,
page:
page
,
}.
to_json
}.
to_json
end
json_output
json_output
end
end
...
...
lib/helpers.rb
View file @
346c65ee
...
@@ -150,27 +150,23 @@ helpers do
...
@@ -150,27 +150,23 @@ helpers do
end
end
if
filter_flagged
if
filter_flagged
self
.
class
.
trace_execution_scoped
([
'Custom/handle_threads_query/find_flagged'
])
do
# TODO replace with aggregate query?
# TODO replace with aggregate query?
comment_ids
=
Comment
.
where
(
:course_id
=>
course_id
).
comment_ids
=
Comment
.
where
(
:course_id
=>
course_id
).
where
(
:abuse_flaggers
.
ne
=>
[],
:abuse_flaggers
.
exists
=>
true
).
where
(
:abuse_flaggers
.
ne
=>
[],
:abuse_flaggers
.
exists
=>
true
).
collect
{
|
c
|
c
.
comment_thread_id
}.
uniq
collect
{
|
c
|
c
.
comment_thread_id
}.
uniq
thread_ids
=
comment_threads
.
where
(
:abuse_flaggers
.
ne
=>
[],
:abuse_flaggers
.
exists
=>
true
).
thread_ids
=
comment_threads
.
where
(
:abuse_flaggers
.
ne
=>
[],
:abuse_flaggers
.
exists
=>
true
).
collect
{
|
c
|
c
.
id
}
collect
{
|
c
|
c
.
id
}
comment_threads
=
comment_threads
.
in
({
"_id"
=>
(
comment_ids
+
thread_ids
).
uniq
})
comment_threads
=
comment_threads
.
in
({
"_id"
=>
(
comment_ids
+
thread_ids
).
uniq
})
end
end
end
if
filter_unanswered
if
filter_unanswered
self
.
class
.
trace_execution_scoped
([
'Custom/handle_threads_query/find_unanswered'
])
do
endorsed_thread_ids
=
Comment
.
where
(
:course_id
=>
course_id
).
endorsed_thread_ids
=
Comment
.
where
(
:course_id
=>
course_id
).
where
(
:parent_id
.
exists
=>
false
,
:endorsed
=>
true
).
where
(
:parent_id
.
exists
=>
false
,
:endorsed
=>
true
).
collect
{
|
c
|
c
.
comment_thread_id
}.
uniq
collect
{
|
c
|
c
.
comment_thread_id
}.
uniq
comment_threads
=
comment_threads
.
where
({
"thread_type"
=>
:question
}).
nin
({
"_id"
=>
endorsed_thread_ids
})
comment_threads
=
comment_threads
.
where
({
"thread_type"
=>
:question
}).
nin
({
"_id"
=>
endorsed_thread_ids
})
end
end
end
sort_criteria
=
get_sort_criteria
(
sort_key
)
sort_criteria
=
get_sort_criteria
(
sort_key
)
...
...
models/user.rb
View file @
346c65ee
...
@@ -50,61 +50,59 @@ class User
...
@@ -50,61 +50,59 @@ class User
end
end
if
params
[
:course_id
]
if
params
[
:course_id
]
self
.
class
.
trace_execution_scoped
([
'Custom/User.to_hash/count_comments_and_threads'
])
do
if
not
params
[
:group_ids
].
empty?
if
not
params
[
:group_ids
].
empty?
# Get threads in either the specified group(s) or posted to all groups (nil).
# Get threads in either the specified group(s) or posted to all groups (nil).
specified_groups_or_global
=
params
[
:group_ids
]
<<
nil
specified_groups_or_global
=
params
[
:group_ids
]
<<
nil
threads_count
=
CommentThread
.
course_context
.
where
(
threads_count
=
CommentThread
.
course_context
.
where
(
author_id:
id
,
author_id:
id
,
course_id:
params
[
:course_id
],
course_id:
params
[
:course_id
],
group_id:
{
"$in"
=>
specified_groups_or_global
},
group_id:
{
"$in"
=>
specified_groups_or_global
},
anonymous:
false
,
anonymous:
false
,
anonymous_to_peers:
false
anonymous_to_peers:
false
).
count
).
count
# Note that the comments may have been responses to a thread not started by author_id.
# Note that the comments may have been responses to a thread not started by author_id.
# comment.standalone_context? gets the context from the parent comment_thread
# comment.standalone_context? gets the context from the parent comment_thread
# we need to eager load the comment_thread to prevent an N+1 when we iterate through the results
# we need to eager load the comment_thread to prevent an N+1 when we iterate through the results
comment_thread_ids
=
Comment
.
includes
(
:comment_thread
).
where
(
comment_thread_ids
=
Comment
.
includes
(
:comment_thread
).
where
(
author_id:
id
,
author_id:
id
,
course_id:
params
[
:course_id
],
course_id:
params
[
:course_id
],
anonymous:
false
,
anonymous:
false
,
anonymous_to_peers:
false
anonymous_to_peers:
false
).
).
reject
{
|
comment
|
comment
.
standalone_context?
}.
reject
{
|
comment
|
comment
.
standalone_context?
}.
collect
{
|
comment
|
comment
.
comment_thread_id
}
collect
{
|
comment
|
comment
.
comment_thread_id
}
# Filter to the unique thread ids visible to the specified group(s).
# Filter to the unique thread ids visible to the specified group(s).
group_comment_thread_ids
=
CommentThread
.
where
(
group_comment_thread_ids
=
CommentThread
.
where
(
id:
{
"$in"
=>
comment_thread_ids
.
uniq
},
id:
{
"$in"
=>
comment_thread_ids
.
uniq
},
group_id:
{
"$in"
=>
specified_groups_or_global
},
group_id:
{
"$in"
=>
specified_groups_or_global
},
).
collect
{
|
d
|
d
.
id
}
).
collect
{
|
d
|
d
.
id
}
# Now filter comment_thread_ids so it only includes things in group_comment_thread_ids
# Now filter comment_thread_ids so it only includes things in group_comment_thread_ids
# (keeping duplicates so the count will be correct).
# (keeping duplicates so the count will be correct).
comments_count
=
comment_thread_ids
.
count
{
comments_count
=
comment_thread_ids
.
count
{
|
comment_thread_id
|
group_comment_thread_ids
.
include?
(
comment_thread_id
)
|
comment_thread_id
|
group_comment_thread_ids
.
include?
(
comment_thread_id
)
}
}
else
else
threads_count
=
CommentThread
.
course_context
.
where
(
threads_count
=
CommentThread
.
course_context
.
where
(
author_id:
id
,
author_id:
id
,
course_id:
params
[
:course_id
],
course_id:
params
[
:course_id
],
anonymous:
false
,
anonymous:
false
,
anonymous_to_peers:
false
anonymous_to_peers:
false
).
count
).
count
# comment.standalone_context? gets the context from the parent comment_thread
# comment.standalone_context? gets the context from the parent comment_thread
# we need to eager load the comment_thread to prevent an N+1 when we iterate through the results
# we need to eager load the comment_thread to prevent an N+1 when we iterate through the results
comments_count
=
Comment
.
includes
(
:comment_thread
).
where
(
comments_count
=
Comment
.
includes
(
:comment_thread
).
where
(
author_id:
id
,
author_id:
id
,
course_id:
params
[
:course_id
],
course_id:
params
[
:course_id
],
anonymous:
false
,
anonymous:
false
,
anonymous_to_peers:
false
anonymous_to_peers:
false
).
reject
{
|
comment
|
comment
.
standalone_context?
}.
count
).
reject
{
|
comment
|
comment
.
standalone_context?
}.
count
end
hash
=
hash
.
merge!
(
"threads_count"
=>
threads_count
,
"comments_count"
=>
comments_count
)
end
end
hash
=
hash
.
merge!
(
"threads_count"
=>
threads_count
,
"comments_count"
=>
comments_count
)
end
end
hash
hash
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