Performance improvements, rename scopes to standard
This commit is contained in:
parent
301f64c350
commit
52ea4a73c8
|
|
@ -9,7 +9,7 @@ use Backend\Models\UserPreferences;
|
|||
*
|
||||
* Usage:
|
||||
*
|
||||
* In the model class definition:
|
||||
* In the model class definition:
|
||||
*
|
||||
* public $implement = ['Backend.Behaviors.UserPreferencesModel'];
|
||||
* public $settingsCode = 'author.plugin::code';
|
||||
|
|
@ -62,7 +62,8 @@ class UserPreferencesModel extends SettingsModel
|
|||
public function getSettingsRecord()
|
||||
{
|
||||
$item = UserPreferences::forUser();
|
||||
$record = $item->scopeFindRecord($this->model, $this->recordCode, $item->userContext)
|
||||
$record = $item
|
||||
->scopeApplyKeyAndUser($this->model, $this->recordCode, $item->userContext)
|
||||
->remember(1440, $this->getCacheKey())
|
||||
->first();
|
||||
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ class Theme
|
|||
|
||||
if (DbDongle::hasDatabase()) {
|
||||
$dbResult = Cache::remember(self::ACTIVE_KEY, 1440, function() {
|
||||
return Parameters::findRecord(self::ACTIVE_KEY)->pluck('value');
|
||||
return Parameters::applyKey(self::ACTIVE_KEY)->pluck('value');
|
||||
});
|
||||
|
||||
if ($dbResult !== null && static::exists($dbResult)) {
|
||||
|
|
|
|||
|
|
@ -4,14 +4,6 @@ Scoreboard
|
|||
|
||||
# Example
|
||||
|
||||
<script src="/assets/js/october.goalmeter.js"></script>
|
||||
<script src="/assets/js/vendor/raphael-min.js"></script>
|
||||
<script src="/assets/js/october.chartutils.js"></script>
|
||||
<script src="/assets/js/october.chartpie.js"></script>
|
||||
<script src="/assets/js/october.chartbar.js"></script>
|
||||
<script src="/assets/js/october.dragscroll.js"></script>
|
||||
<script src="/assets/js/october.toolbar.js"></script>
|
||||
|
||||
<div class="scoreboard">
|
||||
<div data-control="toolbar">
|
||||
<div class="scoreboard-item control-chart" data-control="chart-pie">
|
||||
|
|
|
|||
|
|
@ -63,7 +63,6 @@ class SettingsModel extends ModelBehavior
|
|||
/*
|
||||
* Parse the config
|
||||
*/
|
||||
$this->fieldConfig = $this->makeConfig($this->model->settingsFields);
|
||||
$this->recordCode = $this->model->settingsCode;
|
||||
}
|
||||
|
||||
|
|
@ -236,7 +235,11 @@ class SettingsModel extends ModelBehavior
|
|||
*/
|
||||
public function getFieldConfig()
|
||||
{
|
||||
return $this->fieldConfig;
|
||||
if ($this->fieldConfig !== null) {
|
||||
return $this->fieldConfig;
|
||||
}
|
||||
|
||||
return $this->fieldConfig = $this->makeConfig($this->model->settingsFields);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class Updates extends Controller
|
|||
$this->vars['projectId'] = Parameters::get('system::project.id');
|
||||
$this->vars['projectName'] = Parameters::get('system::project.name');
|
||||
$this->vars['projectOwner'] = Parameters::get('system::project.owner');
|
||||
$this->vars['pluginsActiveCount'] = PluginVersion::isEnabled()->count();
|
||||
$this->vars['pluginsActiveCount'] = PluginVersion::applyEnabled()->count();
|
||||
$this->vars['pluginsCount'] = PluginVersion::count();
|
||||
return $this->asExtension('ListController')->index();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
<?php namespace System\Models;
|
||||
|
||||
use Exception;
|
||||
use Cache;
|
||||
use October\Rain\Database\Model;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Parameters model
|
||||
|
|
@ -28,6 +29,14 @@ class Parameters extends Model
|
|||
*/
|
||||
protected $jsonable = ['value'];
|
||||
|
||||
/**
|
||||
* Clear the cache after saving.
|
||||
*/
|
||||
public function afterSave()
|
||||
{
|
||||
Cache::forget(implode('-', [$this->table, $this->namespace, $this->group, $this->item]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a setting value by the module (or plugin) name and setting name.
|
||||
* @param string $key Specifies the setting key value, for example 'system:updates.check'
|
||||
|
|
@ -40,7 +49,7 @@ class Parameters extends Model
|
|||
return static::$cache[$key];
|
||||
}
|
||||
|
||||
$record = static::findRecord($key)->first();
|
||||
$record = static::findRecord($key);
|
||||
if (!$record) {
|
||||
return static::$cache[$key] = $default;
|
||||
}
|
||||
|
|
@ -62,7 +71,7 @@ class Parameters extends Model
|
|||
return true;
|
||||
}
|
||||
|
||||
$record = static::findRecord($key)->first();
|
||||
$record = static::findRecord($key);
|
||||
if (!$record) {
|
||||
$record = new static;
|
||||
list($namespace, $group, $item) = $record->parseKey($key);
|
||||
|
|
@ -78,20 +87,36 @@ class Parameters extends Model
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a record (cached)
|
||||
* @return self
|
||||
*/
|
||||
public static function findRecord($key)
|
||||
{
|
||||
$record = new static;
|
||||
|
||||
list($namespace, $group, $item) = $record->parseKey($key);
|
||||
|
||||
return $record
|
||||
->applyKey($key)
|
||||
->remember(5, implode('-', [$record->getTable(), $namespace, $group, $item]))
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to find a setting record for the specified module (or plugin) name and setting name.
|
||||
* @param string $key Specifies the setting key value, for example 'system:updates.check'
|
||||
* @param mixed $default The default value to return if the setting doesn't exist in the DB.
|
||||
* @return mixed Returns the found record or null.
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function scopeFindRecord($query, $key)
|
||||
public function scopeApplyKey($query, $key)
|
||||
{
|
||||
list($namespace, $group, $item) = $this->parseKey($key);
|
||||
|
||||
$query = $query
|
||||
->where('namespace', $namespace)
|
||||
->where('group', $group)
|
||||
->where('item', $item);
|
||||
->where('namespace', $namespace)
|
||||
->where('group', $group)
|
||||
->where('item', $item);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ class PluginVersion extends Model
|
|||
* @param $query
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopeIsEnabled($query)
|
||||
public function scopeApplyEnabled($query)
|
||||
{
|
||||
return $query->where('is_disabled', '!=', 1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue