FEATURE: cache most used SQL queries

This commit is contained in:
Michal Kváček
2017-02-22 01:40:26 +01:00
parent cad205960d
commit f3b1951d25
10 changed files with 74 additions and 35 deletions
+14 -10
View File
@@ -6,6 +6,7 @@ use App\Models\Content\Content;
use App\Models\Module;
use App\Models\User;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Cache;
class CurrentTemplate implements TemplateHandler
{
@@ -20,16 +21,19 @@ class CurrentTemplate implements TemplateHandler
public static function get()
{
if (!self::$initialized) {
try {
self::$template = Module::where('is_template', true)
->where('enabled', true)
->first();
} catch (QueryException $e) {
throw new \ErrorException('DB not migrated, please, do so!');
}
if (self::$template) {
self::$template->module_settings = json_decode(self::$template->module_settings);
}
self::$template = Cache::rememberForever('current-template', function () {
$template = Module::where('is_template', true)
->where('enabled', true)
->first();
// todo remove after adding $casts into Module model
if ($template) {
$template->module_settings = json_decode($template->module_settings);
}
return $template;
});
self::$initialized = true;
}