Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Зуев Егор
/
wiki.dev
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
Dan Brown
2017-02-05 18:57:57 +0000
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
65899a3e91911d7e7199eae8e33cb5f4fa6ce929
65899a3e
1 parent
86625a76
Prevented settings being overfetched from db/cache
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
6 deletions
app/Providers/AppServiceProvider.php
app/Services/SettingService.php
app/helpers.php
app/Providers/AppServiceProvider.php
View file @
65899a3
<?php
namespace
BookStack\Providers
;
use
BookStack\Services\SettingService
;
use
BookStack\Setting
;
use
Illuminate\Support\ServiceProvider
;
use
Validator
;
...
...
@@ -30,6 +32,8 @@ class AppServiceProvider extends ServiceProvider
*/
public
function
register
()
{
//
$this
->
app
->
singleton
(
SettingService
::
class
,
function
(
$app
)
{
return
new
SettingService
(
$app
->
make
(
Setting
::
class
),
$app
->
make
(
'Illuminate\Contracts\Cache\Repository'
));
});
}
}
...
...
app/Services/SettingService.php
View file @
65899a3
...
...
@@ -16,6 +16,7 @@ class SettingService
protected
$setting
;
protected
$cache
;
protected
$localCache
=
[];
protected
$cachePrefix
=
'setting-'
;
...
...
@@ -40,8 +41,12 @@ class SettingService
public
function
get
(
$key
,
$default
=
false
)
{
if
(
$default
===
false
)
$default
=
config
(
'setting-defaults.'
.
$key
,
false
);
if
(
isset
(
$this
->
localCache
[
$key
]))
return
$this
->
localCache
[
$key
];
$value
=
$this
->
getValueFromStore
(
$key
,
$default
);
return
$this
->
formatValue
(
$value
,
$default
);
$formatted
=
$this
->
formatValue
(
$value
,
$default
);
$this
->
localCache
[
$key
]
=
$formatted
;
return
$formatted
;
}
/**
...
...
@@ -71,9 +76,8 @@ class SettingService
// Check the cache
$cacheKey
=
$this
->
cachePrefix
.
$key
;
if
(
$this
->
cache
->
has
(
$cacheKey
))
{
return
$this
->
cache
->
get
(
$cacheKey
);
}
$cacheVal
=
$this
->
cache
->
get
(
$cacheKey
,
null
);
if
(
$cacheVal
!==
null
)
return
$cacheVal
;
// Check the database
$settingObject
=
$this
->
getSettingObjectByKey
(
$key
);
...
...
app/helpers.php
View file @
65899a3
...
...
@@ -64,7 +64,7 @@ function userCan($permission, Ownable $ownable = null)
*/
function
setting
(
$key
=
null
,
$default
=
false
)
{
$settingService
=
app
(
\BookStack\Services\SettingService
::
class
);
$settingService
=
resolve
(
\BookStack\Services\SettingService
::
class
);
if
(
is_null
(
$key
))
return
$settingService
;
return
$settingService
->
get
(
$key
,
$default
);
}
...
...
Please
register
or
sign in
to post a comment