Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
9befa6b9b34c
Commit
8ad1f8a4
authored
Nov 27, 2011
by
Dmitriy Zaporozhets
Browse files
activities page caching
parent
4e4dbdbdf08e
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/controllers/projects_controller.rb
View file @
9befa6b9
...
...
@@ -67,7 +67,7 @@ def update
def
show
return
render
"projects/empty"
unless
@project
.
repo_exists?
limit
=
(
params
[
:limit
]
||
20
).
to_i
@activities
=
@project
.
updates
(
limit
)
@activities
=
@project
.
cached_
updates
(
limit
)
end
#
...
...
app/models/project.rb
View file @
9befa6b9
...
...
@@ -143,6 +143,23 @@ def last_activity_date
last_activity
.
try
(
:created_at
)
end
# Get project updates from cache
# or calculate.
def
cached_updates
(
limit
,
expire
=
2
.
minutes
)
activities_key
=
"project_
#{
id
}
_activities"
cached_activities
=
Rails
.
cache
.
read
(
activities_key
)
if
cached_activities
activities
=
cached_activities
else
activities
=
updates
(
limit
)
Rails
.
cache
.
write
(
activities_key
,
activities
,
:expires_in
=>
60
.
seconds
)
end
activities
end
# Get 20 events for project like
# commits, issues or notes
def
updates
(
n
=
3
)
[
fresh_commits
(
n
),
...
...
config/environments/production.rb
View file @
9befa6b9
...
...
@@ -37,7 +37,7 @@
# config.logger = SyslogLogger.new
# Use a different cache store in production
#
config.cache_store = :mem
_cache
_store
config
.
cache_store
=
:mem
ory
_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
...
...
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