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
c4e15408
Commit
c4e15408
authored
Aug 18, 2012
by
dementrock
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'benchmark' of github.com:rll/cs_comments_service into benchmark
parents
b316c9a5
c12cc34a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
0 deletions
+26
-0
config/application.yml
+1
-0
lib/helpers.rb
+25
-0
No files found.
config/application.yml
View file @
c4e15408
...
@@ -2,3 +2,4 @@ level_limit: 3
...
@@ -2,3 +2,4 @@ level_limit: 3
cache_enabled
:
true
cache_enabled
:
true
cache_timeout
:
cache_timeout
:
threads_search
:
60
threads_search
:
60
threads_query
:
60
lib/helpers.rb
View file @
c4e15408
...
@@ -68,6 +68,23 @@ helpers do
...
@@ -68,6 +68,23 @@ helpers do
end
end
def
handle_threads_query
(
comment_threads
)
def
handle_threads_query
(
comment_threads
)
if
CommentService
.
config
[
:cache_enabled
]
query_params
=
params
.
slice
(
*
%w[course_id commentable_id sort_key sort_order page per_page]
)
memcached_key
=
"threads_query_
#{
query_params
.
hash
}
"
cached_results
=
Sinatra
::
Application
.
cache
.
get
(
memcached_key
)
if
cached_results
puts
"cache hit"
return
{
collection:
cached_results
[
:collection_ids
].
map
{
|
id
|
CommentThread
.
find
(
id
).
to_hash
(
recursive:
bool_recursive
)},
num_pages:
cached_results
[
:num_pages
],
page:
cached_results
[
:page
],
}
end
end
puts
"cache miss"
sort_key_mapper
=
{
sort_key_mapper
=
{
"date"
=>
:created_at
,
"date"
=>
:created_at
,
"activity"
=>
:last_activity_at
,
"activity"
=>
:last_activity_at
,
...
@@ -92,6 +109,14 @@ helpers do
...
@@ -92,6 +109,14 @@ helpers do
num_pages
=
[
1
,
(
comment_threads
.
count
/
per_page
.
to_f
).
ceil
].
max
num_pages
=
[
1
,
(
comment_threads
.
count
/
per_page
.
to_f
).
ceil
].
max
page
=
[
num_pages
,
[
1
,
page
].
max
].
min
page
=
[
num_pages
,
[
1
,
page
].
max
].
min
paged_comment_threads
=
comment_threads
.
page
(
page
).
per
(
per_page
)
paged_comment_threads
=
comment_threads
.
page
(
page
).
per
(
per_page
)
if
CommentService
.
config
[
:cache_enabled
]
cached_results
=
{
collection_ids:
paged_comment_threads
.
map
(
&
:id
),
num_pages:
num_pages
,
page:
page
,
}.
to_json
Sinatra
::
Application
.
cache
.
set
(
memcached_key
,
cached_results
,
CommentService
.
config
[
:cache_timeout
][
:threads_query
].
to_i
)
end
{
{
collection:
paged_comment_threads
.
map
{
|
t
|
t
.
to_hash
(
recursive:
bool_recursive
)},
collection:
paged_comment_threads
.
map
{
|
t
|
t
.
to_hash
(
recursive:
bool_recursive
)},
num_pages:
num_pages
,
num_pages:
num_pages
,
...
...
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