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
c8204217
Commit
c8204217
authored
Sep 04, 2012
by
David Ormsbee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a few more indexes, make some explicit queries to make sure we're using those indexes.
parent
2fd29112
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
5 deletions
+12
-5
models/comment.rb
+2
-0
models/comment_thread.rb
+2
-0
models/subscription.rb
+2
-0
models/user.rb
+6
-5
No files found.
models/comment.rb
View file @
c8204217
...
@@ -15,6 +15,8 @@ class Comment < Content
...
@@ -15,6 +15,8 @@ class Comment < Content
field
:anonymous
,
type:
Boolean
,
default:
false
field
:anonymous
,
type:
Boolean
,
default:
false
field
:at_position_list
,
type:
Array
,
default:
[]
field
:at_position_list
,
type:
Array
,
default:
[]
index
({
author_id:
1
,
course_id:
1
})
belongs_to
:comment_thread
,
index:
true
belongs_to
:comment_thread
,
index:
true
belongs_to
:author
,
class_name:
"User"
,
index:
true
belongs_to
:author
,
class_name:
"User"
,
index:
true
...
...
models/comment_thread.rb
View file @
c8204217
...
@@ -21,6 +21,8 @@ class CommentThread < Content
...
@@ -21,6 +21,8 @@ class CommentThread < Content
field
:at_position_list
,
type:
Array
,
default:
[]
field
:at_position_list
,
type:
Array
,
default:
[]
field
:last_activity_at
,
type:
Time
field
:last_activity_at
,
type:
Time
index
({
author_id:
1
,
course_id:
1
})
include
Tire
::
Model
::
Search
include
Tire
::
Model
::
Search
include
Tire
::
Model
::
Callbacks
include
Tire
::
Model
::
Callbacks
...
...
models/subscription.rb
View file @
c8204217
...
@@ -7,6 +7,8 @@ class Subscription
...
@@ -7,6 +7,8 @@ class Subscription
field
:source_type
,
type:
String
field
:source_type
,
type:
String
index
({
subscriber_id:
1
,
source_id:
1
,
source_type:
1
})
index
({
subscriber_id:
1
,
source_id:
1
,
source_type:
1
})
index
({
subscriber_id:
1
,
source_type:
1
})
index
({
subscriber_id:
1
})
def
to_hash
def
to_hash
as_document
.
slice
(
*
%w[subscriber_id source_id source_type]
)
as_document
.
slice
(
*
%w[subscriber_id source_id source_type]
)
...
...
models/user.rb
View file @
c8204217
...
@@ -31,7 +31,7 @@ class User
...
@@ -31,7 +31,7 @@ class User
end
end
def
subscribed_thread_ids
def
subscribed_thread_ids
subscriptions_as_subscriber
.
where
(
source_type:
"CommentThread"
).
only
(
:source_id
).
map
(
&
:source_id
)
Subscription
.
where
(
subscriber_id:
id
.
to_s
,
source_type:
"CommentThread"
).
only
(
:source_id
).
map
(
&
:source_id
)
end
end
def
subscribed_commentable_ids
def
subscribed_commentable_ids
...
@@ -47,7 +47,7 @@ class User
...
@@ -47,7 +47,7 @@ class User
end
end
def
subscribed_commentables
def
subscribed_commentables
Commentable
.
where
(
:id
.
in
=>
subscribed_commentable_ids
).
only
(
:id
).
map
(
&
:id
)
Commentable
.
find
(
*
subscribed_commentable_ids
).
only
(
:id
).
map
(
&
:id
)
end
end
def
subscribed_users
def
subscribed_users
...
@@ -64,11 +64,12 @@ class User
...
@@ -64,11 +64,12 @@ class User
"id"
=>
id
,
"id"
=>
id
,
"upvoted_ids"
=>
upvoted_ids
,
"upvoted_ids"
=>
upvoted_ids
,
"downvoted_ids"
=>
downvoted_ids
,
"downvoted_ids"
=>
downvoted_ids
,
"default_sort_key"
=>
default_sort_key
)
"default_sort_key"
=>
default_sort_key
)
end
end
if
params
[
:course_id
]
if
params
[
:course_id
]
hash
=
hash
.
merge
(
"threads_count"
=>
comment_threads
.
where
(
course_id:
params
[
:course_id
]).
count
,
hash
=
hash
.
merge
(
"threads_count"
=>
CommentThread
.
where
(
user_id:
id
,
course_id:
params
[
:course_id
]).
count
,
"comments_count"
=>
comments
.
where
(
course_id:
params
[
:course_id
]).
count
,
"comments_count"
=>
Comment
.
where
(
user_id:
id
,
course_id:
params
[
:course_id
]).
count
)
)
end
end
hash
hash
...
...
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