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
01082334
Commit
01082334
authored
Oct 09, 2013
by
jimabramson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove / consolidate queries and adjust indexing to optimize user api
performance.
parent
f8cedf4d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
14 additions
and
30 deletions
+14
-30
models/comment.rb
+0
-1
models/comment_thread.rb
+0
-1
models/content.rb
+1
-0
models/subscription.rb
+1
-0
models/user.rb
+6
-28
scripts/db/migrate-003-update-indexes.js
+3
-0
scripts/db/revert-migrate-003-update-indexes.js
+3
-0
No files found.
models/comment.rb
View file @
01082334
...
...
@@ -3,7 +3,6 @@ require_relative 'content'
class
Comment
<
Content
include
Mongoid
::
Tree
include
Mongo
::
Voteable
include
Mongoid
::
Timestamps
include
Mongoid
::
MagicCounterCache
...
...
models/comment_thread.rb
View file @
01082334
...
...
@@ -2,7 +2,6 @@ require_relative 'content'
class
CommentThread
<
Content
include
Mongo
::
Voteable
include
Mongoid
::
Timestamps
include
Mongoid
::
TaggableWithContext
include
Mongoid
::
TaggableWithContext
::
AggregationStrategy
::
RealTime
...
...
models/content.rb
View file @
01082334
class
Content
include
Mongoid
::
Document
include
Mongo
::
Voteable
field
:visible
,
type:
Boolean
,
default:
true
field
:abuse_flaggers
,
type:
Array
,
default:
[]
...
...
models/subscription.rb
View file @
01082334
...
...
@@ -9,6 +9,7 @@ class Subscription
index
({
subscriber_id:
1
,
source_id:
1
,
source_type:
1
})
index
({
subscriber_id:
1
,
source_type:
1
})
index
({
subscriber_id:
1
})
index
({
source_id:
1
,
source_type:
1
},
{
background:
true
})
def
to_hash
as_document
.
slice
(
*
%w[subscriber_id source_id source_type]
)
...
...
models/user.rb
View file @
01082334
...
...
@@ -23,47 +23,27 @@ class User
validates_uniqueness_of
:username
validates_uniqueness_of
:email
index
external_id:
1
index
(
{
external_id:
1
},
{
unique:
true
,
background:
true
}
)
def
subscriptions_as_source
Subscription
.
where
(
source_id:
id
.
to_s
,
source_type:
self
.
class
.
to_s
)
end
def
subscriptions_as_subscriber
Subscription
.
where
(
subscriber_id:
id
.
to_s
)
end
def
subscribed_thread_ids
Subscription
.
where
(
subscriber_id:
id
.
to_s
,
source_type:
"CommentThread"
).
only
(
:source_id
).
map
(
&
:source_id
)
end
def
subscribed_commentable_ids
subscriptions_as_subscriber
.
where
(
source_type:
"Commentable"
).
only
(
:source_id
).
map
(
&
:source_id
)
end
def
subscribed_user_ids
subscriptions_as_subscriber
.
where
(
source_type:
"User"
).
only
(
:source_id
).
map
(
&
:source_id
)
end
def
subscribed_threads
CommentThread
.
where
(
:id
.
in
=>
subscribed_thread_ids
)
end
def
subscribed_commentables
Commentable
.
find
(
*
subscribed_commentable_ids
).
only
(
:id
).
map
(
&
:id
)
end
def
subscribed_users
subscribed_user_ids
.
map
{
|
id
|
User
.
find
(
id
)}
end
def
to_hash
(
params
=
{})
hash
=
as_document
.
slice
(
*
%w[username external_id]
)
if
params
[
:complete
]
hash
=
hash
.
merge
(
"subscribed_thread_ids"
=>
subscribed_thread_ids
,
"subscribed_commentable_ids"
=>
subscribed_commentable_ids
,
"subscribed_user_ids"
=>
subscribed_user_ids
,
"follower_ids"
=>
subscriptions_as_source
.
only
(
:subscriber_id
).
map
(
&
:subscriber_id
),
"subscribed_commentable_ids"
=>
[],
# not used by comment client. To be removed once removed from comment client.
"subscribed_user_ids"
=>
[],
# ditto.
"follower_ids"
=>
[],
# ditto.
"id"
=>
id
,
"upvoted_ids"
=>
upvoted_ids
,
"downvoted_ids"
=>
downvoted_ids
,
...
...
@@ -81,11 +61,11 @@ class User
end
def
upvoted_ids
Co
mment
.
up_voted_by
(
self
).
map
(
&
:id
)
+
CommentThread
.
up_voted_by
(
self
).
map
(
&
:id
)
Co
ntent
.
up_voted_by
(
self
).
map
(
&
:id
)
end
def
downvoted_ids
Co
mment
.
down_voted_by
(
self
).
map
(
&
:id
)
+
CommentThread
.
down_voted_by
(
self
).
map
(
&
:id
)
Co
ntent
.
down_voted_by
(
self
).
map
(
&
:id
)
end
def
followers
...
...
@@ -115,8 +95,6 @@ class User
include
::
NewRelic
::
Agent
::
MethodTracer
add_method_tracer
:to_hash
add_method_tracer
:subscribed_thread_ids
add_method_tracer
:subscribed_commentable_ids
add_method_tracer
:subscribed_user_ids
add_method_tracer
:upvoted_ids
add_method_tracer
:downvoted_ids
...
...
scripts/db/migrate-003-update-indexes.js
0 → 100644
View file @
01082334
db
.
users
.
dropIndex
({
external_id
:
1
})
// drop the non-unique one
db
.
users
.
ensureIndex
({
external_id
:
1
},
{
unique
:
true
,
background
:
true
})
db
.
subscriptions
.
ensureIndex
({
source_id
:
1
,
source_type
:
1
},
{
background
:
true
})
scripts/db/revert-migrate-003-update-indexes.js
0 → 100644
View file @
01082334
db
.
users
.
dropIndex
({
external_id
:
1
})
// drop the unique one
db
.
users
.
ensureIndex
({
external_id
:
1
},
{
background
:
true
})
db
.
subscriptions
.
dropIndex
({
source_id
:
1
,
source_type
:
1
})
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