From f9ee33ab5aea2b36878f8fe3d19ce3f32465dcab Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 28 Feb 2022 17:01:34 +0100 Subject: [PATCH] wip #5127 --- src/app/Http/Controllers/CubistSelect2Controller.php | 3 ++- src/app/Magic/Fields/SelectFromArray.php | 12 +++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/app/Http/Controllers/CubistSelect2Controller.php b/src/app/Http/Controllers/CubistSelect2Controller.php index 470fda1..e3e1173 100644 --- a/src/app/Http/Controllers/CubistSelect2Controller.php +++ b/src/app/Http/Controllers/CubistSelect2Controller.php @@ -6,6 +6,7 @@ use Cubist\Backpack\Http\Controllers\Base\XSendFileController; use Cubist\Backpack\Magic\Fields\SelectFromArray; use Cubist\Util\Text; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Cache; class CubistSelect2Controller { @@ -19,7 +20,7 @@ class CubistSelect2Controller } $perPage = 10; - $data = json_decode(file_get_contents(storage_path('select2/' . $hash . '.json')), true); + $data = Cache::get('select2_' . $hash); $term = request()->get('q', null); $page = request()->get('page', 1); $offset = ($page - 1) * $perPage; diff --git a/src/app/Magic/Fields/SelectFromArray.php b/src/app/Magic/Fields/SelectFromArray.php index 7b7decc..246e6a4 100644 --- a/src/app/Magic/Fields/SelectFromArray.php +++ b/src/app/Magic/Fields/SelectFromArray.php @@ -6,6 +6,7 @@ namespace Cubist\Backpack\Magic\Fields; use Cubist\Backpack\CubistBackpackServiceProvider; use Cubist\Util\Text; +use Illuminate\Support\Facades\Cache; class SelectFromArray extends Field { @@ -38,18 +39,15 @@ class SelectFromArray extends Field } } - public static function hashOptions($options){ + public static function hashOptions($options) + { $data = []; foreach ($options as $k => $v) { $data[$k] = ['t' => $v, 'n' => self::normalize($v)]; } $hash = hash('sha256', print_r($data, true)); - $name = $hash . '.json'; - $dir = \Cubist\Util\Files\Files::mkdir(storage_path('select2')); - $file = $dir . '/' . $name; - if (!file_exists($file)) { - file_put_contents($file, json_encode($data)); - } + Cache::add('select2_' . $hash, $data, 600); + return $hash; } -- 2.39.5