Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
O
OHR Support
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
97
Issues
97
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
OHR Support
Commits
5a9ffe96
Commit
5a9ffe96
authored
May 27, 2011
by
Eric Davis
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/350-use_rails_cache_for_settings_cache' into unstable
parents
9e1b6c14
e4fac8d4
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
21 additions
and
19 deletions
+21
-19
setting.rb
app/models/setting.rb
+14
-12
documents_controller_test.rb
test/functional/documents_controller_test.rb
+1
-1
news_controller_test.rb
test/functional/news_controller_test.rb
+1
-1
repositories_filesystem_controller_test.rb
test/functional/repositories_filesystem_controller_test.rb
+1
-1
comment_test.rb
test/unit/comment_test.rb
+1
-1
document_test.rb
test/unit/document_test.rb
+1
-1
news_test.rb
test/unit/news_test.rb
+1
-1
repository_filesystem_test.rb
test/unit/repository_filesystem_test.rb
+1
-1
No files found.
app/models/setting.rb
View file @
5a9ffe96
...
...
@@ -85,10 +85,6 @@ class Setting < ActiveRecord::Base
validates_inclusion_of
:name
,
:in
=>
@@available_settings
.
keys
validates_numericality_of
:value
,
:only_integer
=>
true
,
:if
=>
Proc
.
new
{
|
setting
|
@@available_settings
[
setting
.
name
][
'format'
]
==
'int'
}
# Hash used to cache setting values
@cached_settings
=
{}
@cached_cleared_on
=
Time
.
now
def
value
v
=
read_attribute
(
:value
)
# Unserialize serialized settings
...
...
@@ -104,16 +100,15 @@ class Setting < ActiveRecord::Base
# Returns the value of the setting named name
def
self
.
[]
(
name
)
v
=
@cached_settings
[
name
]
v
?
v
:
(
@cached_settings
[
name
]
=
find_or_default
(
name
).
value
)
Marshal
.
load
(
Rails
.
cache
.
fetch
(
"chiliproject/setting/
#{
name
}
"
)
{
Marshal
.
dump
(
find_or_default
(
name
).
value
)}).
freeze
end
def
self
.
[]=
(
name
,
v
)
setting
=
find_or_default
(
name
)
setting
.
value
=
(
v
?
v
:
""
)
@cached_settings
[
name
]
=
nil
Rails
.
cache
.
delete
"chiliproject/setting/
#{
name
}
"
setting
.
save
setting
.
value
setting
.
value
.
freeze
end
# Defines getter and setter for each setting
...
...
@@ -150,11 +145,18 @@ class Setting < ActiveRecord::Base
# Called once per request
def
self
.
check_cache
settings_updated_on
=
Setting
.
maximum
(
:updated_on
)
if
settings_updated_on
&&
@cached_cleared_on
<=
settings_updated_on
@cached_settings
.
clear
@cached_cleared_on
=
Time
.
now
logger
.
info
"Settings cache cleared."
if
logger
cache_cleared_on
=
Rails
.
cache
.
read
(
'chiliproject/setting-cleared_on'
)
cache_cleared_on
=
cache_cleared_on
?
Marshal
.
load
(
cache_cleared_on
)
:
Time
.
now
if
settings_updated_on
&&
cache_cleared_on
<=
settings_updated_on
clear_cache
end
end
# Clears all of the Setting caches
def
self
.
clear_cache
Rails
.
cache
.
delete_matched
(
/^chiliproject\/setting\/.+$/
)
Rails
.
cache
.
write
(
'chiliproject/setting-cleared_on'
,
Marshal
.
dump
(
Time
.
now
))
logger
.
info
'Settings cache cleared.'
if
logger
end
private
...
...
test/functional/documents_controller_test.rb
View file @
5a9ffe96
...
...
@@ -67,7 +67,7 @@ LOREM
def
test_new_with_one_attachment
ActionMailer
::
Base
.
deliveries
.
clear
Setting
.
notified_events
<<
'document_added'
Setting
.
notified_events
=
Setting
.
notified_events
.
dup
<<
'document_added'
@request
.
session
[
:user_id
]
=
2
set_tmp_attachments_directory
...
...
test/functional/news_controller_test.rb
View file @
5a9ffe96
...
...
@@ -67,7 +67,7 @@ class NewsControllerTest < ActionController::TestCase
def
test_post_create
ActionMailer
::
Base
.
deliveries
.
clear
Setting
.
notified_events
<<
'news_added'
Setting
.
notified_events
=
Setting
.
notified_events
.
dup
<<
'news_added'
@request
.
session
[
:user_id
]
=
2
post
:create
,
:project_id
=>
1
,
:news
=>
{
:title
=>
'NewsControllerTest'
,
...
...
test/functional/repositories_filesystem_controller_test.rb
View file @
5a9ffe96
...
...
@@ -33,7 +33,7 @@ class RepositoriesFilesystemControllerTest < ActionController::TestCase
@request
=
ActionController
::
TestRequest
.
new
@response
=
ActionController
::
TestResponse
.
new
User
.
current
=
nil
Setting
.
enabled_scm
<<
'Filesystem'
unless
Setting
.
enabled_scm
.
include?
(
'Filesystem'
)
Setting
.
enabled_scm
=
Setting
.
enabled_scm
.
dup
<<
'Filesystem'
unless
Setting
.
enabled_scm
.
include?
(
'Filesystem'
)
@repository
=
Repository
::
Filesystem
.
create
(
:project
=>
Project
.
find
(
PRJ_ID
),
:url
=>
REPOSITORY_PATH
,
...
...
test/unit/comment_test.rb
View file @
5a9ffe96
...
...
@@ -33,7 +33,7 @@ class CommentTest < ActiveSupport::TestCase
end
def
test_create_should_send_notification
Setting
.
notified_events
<<
'news_comment_added'
Setting
.
notified_events
=
Setting
.
notified_events
.
dup
<<
'news_comment_added'
Watcher
.
create!
(
:watchable
=>
@news
,
:user
=>
@jsmith
)
assert_difference
'ActionMailer::Base.deliveries.size'
do
...
...
test/unit/document_test.rb
View file @
5a9ffe96
...
...
@@ -27,7 +27,7 @@ class DocumentTest < ActiveSupport::TestCase
def
test_create_should_send_email_notification
ActionMailer
::
Base
.
deliveries
.
clear
Setting
.
notified_events
<<
'document_added'
Setting
.
notified_events
=
Setting
.
notified_events
.
dup
<<
'document_added'
doc
=
Document
.
new
(
:project
=>
Project
.
find
(
1
),
:title
=>
'New document'
,
:category
=>
Enumeration
.
find_by_name
(
'User documentation'
))
assert
doc
.
save
...
...
test/unit/news_test.rb
View file @
5a9ffe96
...
...
@@ -30,7 +30,7 @@ class NewsTest < ActiveSupport::TestCase
def
test_create_should_send_email_notification
ActionMailer
::
Base
.
deliveries
.
clear
Setting
.
notified_events
<<
'news_added'
Setting
.
notified_events
=
Setting
.
notified_events
.
dup
<<
'news_added'
news
=
Project
.
find
(
:first
).
news
.
new
(
valid_news
)
assert
news
.
save
...
...
test/unit/repository_filesystem_test.rb
View file @
5a9ffe96
...
...
@@ -25,7 +25,7 @@ class RepositoryFilesystemTest < ActiveSupport::TestCase
def
setup
@project
=
Project
.
find
(
3
)
Setting
.
enabled_scm
<<
'Filesystem'
unless
Setting
.
enabled_scm
.
include?
(
'Filesystem'
)
Setting
.
enabled_scm
=
Setting
.
enabled_scm
.
dup
<<
'Filesystem'
unless
Setting
.
enabled_scm
.
include?
(
'Filesystem'
)
assert
@repository
=
Repository
::
Filesystem
.
create
(
:project
=>
@project
,
:url
=>
REPOSITORY_PATH
)
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