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
c51a32ac
Commit
c51a32ac
authored
May 25, 2011
by
Felix Schäfer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Rails.cache to cache application settings.
#350
parent
5c8e04db
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
16 additions
and
19 deletions
+16
-19
setting.rb
app/models/setting.rb
+9
-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 @
c51a32ac
...
@@ -84,10 +84,6 @@ class Setting < ActiveRecord::Base
...
@@ -84,10 +84,6 @@ class Setting < ActiveRecord::Base
validates_uniqueness_of
:name
validates_uniqueness_of
:name
validates_inclusion_of
:name
,
:in
=>
@@available_settings
.
keys
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'
}
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
def
value
v
=
read_attribute
(
:value
)
v
=
read_attribute
(
:value
)
...
@@ -104,16 +100,15 @@ class Setting < ActiveRecord::Base
...
@@ -104,16 +100,15 @@ class Setting < ActiveRecord::Base
# Returns the value of the setting named name
# Returns the value of the setting named name
def
self
.
[]
(
name
)
def
self
.
[]
(
name
)
v
=
@cached_settings
[
name
]
Marshal
.
load
(
Rails
.
cache
.
fetch
(
"chiliproject/setting/
#{
name
}
"
)
{
Marshal
.
dump
(
find_or_default
(
name
).
value
)}).
freeze
v
?
v
:
(
@cached_settings
[
name
]
=
find_or_default
(
name
).
value
)
end
end
def
self
.
[]=
(
name
,
v
)
def
self
.
[]=
(
name
,
v
)
setting
=
find_or_default
(
name
)
setting
=
find_or_default
(
name
)
setting
.
value
=
(
v
?
v
:
""
)
setting
.
value
=
(
v
?
v
:
""
)
@cached_settings
[
name
]
=
nil
Rails
.
cache
.
delete
"chiliproject/setting/
#{
name
}
"
setting
.
save
setting
.
save
setting
.
value
setting
.
value
.
freeze
end
end
# Defines getter and setter for each setting
# Defines getter and setter for each setting
...
@@ -150,10 +145,12 @@ class Setting < ActiveRecord::Base
...
@@ -150,10 +145,12 @@ class Setting < ActiveRecord::Base
# Called once per request
# Called once per request
def
self
.
check_cache
def
self
.
check_cache
settings_updated_on
=
Setting
.
maximum
(
:updated_on
)
settings_updated_on
=
Setting
.
maximum
(
:updated_on
)
if
settings_updated_on
&&
@cached_cleared_on
<=
settings_updated_on
cache_cleared_on
=
Rails
.
cache
.
read
(
'chiliproject/setting-cleared_on'
)
@cached_settings
.
clear
cache_cleared_on
=
cache_cleared_on
?
Marshal
.
load
(
cache_cleared_on
)
:
Time
.
now
@cached_cleared_on
=
Time
.
now
if
settings_updated_on
&&
cache_cleared_on
<=
settings_updated_on
logger
.
info
"Settings cache cleared."
if
logger
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
end
end
end
...
...
test/functional/documents_controller_test.rb
View file @
c51a32ac
...
@@ -67,7 +67,7 @@ LOREM
...
@@ -67,7 +67,7 @@ LOREM
def
test_new_with_one_attachment
def
test_new_with_one_attachment
ActionMailer
::
Base
.
deliveries
.
clear
ActionMailer
::
Base
.
deliveries
.
clear
Setting
.
notified_events
<<
'document_added'
Setting
.
notified_events
=
Setting
.
notified_events
.
dup
<<
'document_added'
@request
.
session
[
:user_id
]
=
2
@request
.
session
[
:user_id
]
=
2
set_tmp_attachments_directory
set_tmp_attachments_directory
...
...
test/functional/news_controller_test.rb
View file @
c51a32ac
...
@@ -67,7 +67,7 @@ class NewsControllerTest < ActionController::TestCase
...
@@ -67,7 +67,7 @@ class NewsControllerTest < ActionController::TestCase
def
test_post_create
def
test_post_create
ActionMailer
::
Base
.
deliveries
.
clear
ActionMailer
::
Base
.
deliveries
.
clear
Setting
.
notified_events
<<
'news_added'
Setting
.
notified_events
=
Setting
.
notified_events
.
dup
<<
'news_added'
@request
.
session
[
:user_id
]
=
2
@request
.
session
[
:user_id
]
=
2
post
:create
,
:project_id
=>
1
,
:news
=>
{
:title
=>
'NewsControllerTest'
,
post
:create
,
:project_id
=>
1
,
:news
=>
{
:title
=>
'NewsControllerTest'
,
...
...
test/functional/repositories_filesystem_controller_test.rb
View file @
c51a32ac
...
@@ -33,7 +33,7 @@ class RepositoriesFilesystemControllerTest < ActionController::TestCase
...
@@ -33,7 +33,7 @@ class RepositoriesFilesystemControllerTest < ActionController::TestCase
@request
=
ActionController
::
TestRequest
.
new
@request
=
ActionController
::
TestRequest
.
new
@response
=
ActionController
::
TestResponse
.
new
@response
=
ActionController
::
TestResponse
.
new
User
.
current
=
nil
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
(
@repository
=
Repository
::
Filesystem
.
create
(
:project
=>
Project
.
find
(
PRJ_ID
),
:project
=>
Project
.
find
(
PRJ_ID
),
:url
=>
REPOSITORY_PATH
,
:url
=>
REPOSITORY_PATH
,
...
...
test/unit/comment_test.rb
View file @
c51a32ac
...
@@ -33,7 +33,7 @@ class CommentTest < ActiveSupport::TestCase
...
@@ -33,7 +33,7 @@ class CommentTest < ActiveSupport::TestCase
end
end
def
test_create_should_send_notification
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
)
Watcher
.
create!
(
:watchable
=>
@news
,
:user
=>
@jsmith
)
assert_difference
'ActionMailer::Base.deliveries.size'
do
assert_difference
'ActionMailer::Base.deliveries.size'
do
...
...
test/unit/document_test.rb
View file @
c51a32ac
...
@@ -27,7 +27,7 @@ class DocumentTest < ActiveSupport::TestCase
...
@@ -27,7 +27,7 @@ class DocumentTest < ActiveSupport::TestCase
def
test_create_should_send_email_notification
def
test_create_should_send_email_notification
ActionMailer
::
Base
.
deliveries
.
clear
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'
))
doc
=
Document
.
new
(
:project
=>
Project
.
find
(
1
),
:title
=>
'New document'
,
:category
=>
Enumeration
.
find_by_name
(
'User documentation'
))
assert
doc
.
save
assert
doc
.
save
...
...
test/unit/news_test.rb
View file @
c51a32ac
...
@@ -30,7 +30,7 @@ class NewsTest < ActiveSupport::TestCase
...
@@ -30,7 +30,7 @@ class NewsTest < ActiveSupport::TestCase
def
test_create_should_send_email_notification
def
test_create_should_send_email_notification
ActionMailer
::
Base
.
deliveries
.
clear
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
)
news
=
Project
.
find
(
:first
).
news
.
new
(
valid_news
)
assert
news
.
save
assert
news
.
save
...
...
test/unit/repository_filesystem_test.rb
View file @
c51a32ac
...
@@ -25,7 +25,7 @@ class RepositoryFilesystemTest < ActiveSupport::TestCase
...
@@ -25,7 +25,7 @@ class RepositoryFilesystemTest < ActiveSupport::TestCase
def
setup
def
setup
@project
=
Project
.
find
(
3
)
@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
(
assert
@repository
=
Repository
::
Filesystem
.
create
(
:project
=>
@project
,
:url
=>
REPOSITORY_PATH
)
:project
=>
@project
,
:url
=>
REPOSITORY_PATH
)
end
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