From 77f455651d9f575a8f520e54580626f77de7d932 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 30 Jan 2016 12:03:28 +0000 Subject: [PATCH 1/4] Work on config caching --- .../Providers/ConfigServiceProvider.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/Foundation/Providers/ConfigServiceProvider.php b/app/Foundation/Providers/ConfigServiceProvider.php index e777300c..5351929a 100644 --- a/app/Foundation/Providers/ConfigServiceProvider.php +++ b/app/Foundation/Providers/ConfigServiceProvider.php @@ -14,6 +14,8 @@ namespace CachetHQ\Cachet\Foundation\Providers; use CachetHQ\Cachet\Config\Repository; use CachetHQ\Cachet\Models\Setting as SettingModel; use Exception; +use Illuminate\Contracts\Console\Kernel; +use Illuminate\Support\Facades\Config; use Illuminate\Support\ServiceProvider; /** @@ -32,6 +34,20 @@ class ConfigServiceProvider extends ServiceProvider */ public function boot() { + if ($this->app->configurationIsCached()) { + if ($this->app->environment() === 'production') { + $this->app->terminating(function () { + if ($this->app->setting->stale()) { + $this->app->make(Kernel::class)->call('config:cache'); + } + }); + } else { + $this->app->make(Kernel::class)->call('config:clear'); + } + + return; + } + try { // Get the default settings. $defaultSettings = $this->app->config->get('setting'); @@ -72,6 +88,12 @@ class ConfigServiceProvider extends ServiceProvider } $this->app->config->set('cors.paths.api/v1/*.allowedOrigins', $allowedOrigins); + + if ($this->app->environment() === 'production') { + $this->app->terminating(function () { + $this->app->make(Kernel::class)->call('config:cache'); + }); + } } /** From 20e4ae5ff8d5775fde7138ed24f48c0e752a3b41 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 24 May 2016 17:00:48 +0100 Subject: [PATCH 2/4] Scaled things back --- .../Providers/ConfigServiceProvider.php | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/app/Foundation/Providers/ConfigServiceProvider.php b/app/Foundation/Providers/ConfigServiceProvider.php index 5351929a..b7665ab7 100644 --- a/app/Foundation/Providers/ConfigServiceProvider.php +++ b/app/Foundation/Providers/ConfigServiceProvider.php @@ -14,8 +14,6 @@ namespace CachetHQ\Cachet\Foundation\Providers; use CachetHQ\Cachet\Config\Repository; use CachetHQ\Cachet\Models\Setting as SettingModel; use Exception; -use Illuminate\Contracts\Console\Kernel; -use Illuminate\Support\Facades\Config; use Illuminate\Support\ServiceProvider; /** @@ -34,26 +32,26 @@ class ConfigServiceProvider extends ServiceProvider */ public function boot() { - if ($this->app->configurationIsCached()) { - if ($this->app->environment() === 'production') { - $this->app->terminating(function () { - if ($this->app->setting->stale()) { - $this->app->make(Kernel::class)->call('config:cache'); - } - }); - } else { - $this->app->make(Kernel::class)->call('config:clear'); - } + $path = $this->app->bootstrapPath().'/cache/cachet.'.$this->app->environment().'.php'; - return; + try { + $cache = $this->app->files->getRequire($path); + } catch (Exception $e) { + $cache = false; } + $this->app->terminating(function () use ($path) { + if ($this->app->setting->stale()) { + $this->app->files->put($path, 'app->setting->all(), true).';'.PHP_EOL); + } + }); + try { // Get the default settings. $defaultSettings = $this->app->config->get('setting'); // Get the configured settings. - $appSettings = $this->app->setting->all(); + $appSettings = $cache === false ? $this->app->setting->all() : $cache; // Merge the settings $settings = array_merge($defaultSettings, $appSettings); @@ -88,12 +86,6 @@ class ConfigServiceProvider extends ServiceProvider } $this->app->config->set('cors.paths.api/v1/*.allowedOrigins', $allowedOrigins); - - if ($this->app->environment() === 'production') { - $this->app->terminating(function () { - $this->app->make(Kernel::class)->call('config:cache'); - }); - } } /** From 4549c5195962f3c97f41445025fe79198d328529 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 24 May 2016 17:12:08 +0100 Subject: [PATCH 3/4] Deal with cases when we have no settings properly --- app/Foundation/Providers/ConfigServiceProvider.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Foundation/Providers/ConfigServiceProvider.php b/app/Foundation/Providers/ConfigServiceProvider.php index b7665ab7..b6d810e7 100644 --- a/app/Foundation/Providers/ConfigServiceProvider.php +++ b/app/Foundation/Providers/ConfigServiceProvider.php @@ -40,9 +40,11 @@ class ConfigServiceProvider extends ServiceProvider $cache = false; } - $this->app->terminating(function () use ($path) { + $this->app->terminating(function () use ($cache, $path) { if ($this->app->setting->stale()) { $this->app->files->put($path, 'app->setting->all(), true).';'.PHP_EOL); + } elseif ($cache === false) { + $this->app->files->put($path, ' Date: Tue, 24 May 2016 17:20:23 +0100 Subject: [PATCH 4/4] Derp fix --- app/Foundation/Providers/ConfigServiceProvider.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/Foundation/Providers/ConfigServiceProvider.php b/app/Foundation/Providers/ConfigServiceProvider.php index b6d810e7..974a59a2 100644 --- a/app/Foundation/Providers/ConfigServiceProvider.php +++ b/app/Foundation/Providers/ConfigServiceProvider.php @@ -41,10 +41,8 @@ class ConfigServiceProvider extends ServiceProvider } $this->app->terminating(function () use ($cache, $path) { - if ($this->app->setting->stale()) { + if ($this->app->setting->stale() || $cache === false) { $this->app->files->put($path, 'app->setting->all(), true).';'.PHP_EOL); - } elseif ($cache === false) { - $this->app->files->put($path, '