From dc70767ba28db39a98a233f14ba765082fca1875 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 15 Jun 2023 09:58:30 +0200 Subject: [PATCH] wip #5996 @0.25 --- .docker/dev/docker-compose.yml | 1 + .docker/dev/update.sh | 4 +- app/Console/Commands/ToolboxPrecache.php | 2 + app/Models/FluidbookTranslate.php | 48 +++++++++++++----------- 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/.docker/dev/docker-compose.yml b/.docker/dev/docker-compose.yml index e15993158..89381c72c 100644 --- a/.docker/dev/docker-compose.yml +++ b/.docker/dev/docker-compose.yml @@ -69,6 +69,7 @@ services: networks: - fluidbook-toolbox-dev - fluidbook-processfarm + privileged: true restart: unless-stopped webserver: diff --git a/.docker/dev/update.sh b/.docker/dev/update.sh index 724bf3917..7c00c55e6 100644 --- a/.docker/dev/update.sh +++ b/.docker/dev/update.sh @@ -1,10 +1,10 @@ #!/bin/sh cd /docker/fluidbook-toolbox-dev -/home/toolbox/dev/scripts/fixrights.sh +/home/toolbox/www/scripts/fixrights.sh chown root:root /home/toolbox/dev/.docker/config/cron/host;ln -sf /home/toolbox/dev/.docker/config/cron/host /etc/cron.d/toolbox docker network create fluidbook-toolbox-dev docker compose down docker compose up -d -/home/toolbox/dev/scripts/fixrights.sh +/home/toolbox/www/scripts/fixrights.sh docker exec -it fluidbook-toolbox /application/scripts/update.sh diff --git a/app/Console/Commands/ToolboxPrecache.php b/app/Console/Commands/ToolboxPrecache.php index 14016e88a..621684005 100644 --- a/app/Console/Commands/ToolboxPrecache.php +++ b/app/Console/Commands/ToolboxPrecache.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use App\Fluidbook\Farm; +use App\Models\FluidbookTranslate; use Cubedesigners\UserDatabase\Permissions; use Cubist\Backpack\Console\Commands\CubistCommand; @@ -15,5 +16,6 @@ class ToolboxPrecache extends CubistCommand { // Users tree Permissions::_getData(true); + FluidbookTranslate::getAllFluidbookTranslations(true); } } diff --git a/app/Models/FluidbookTranslate.php b/app/Models/FluidbookTranslate.php index 05fc6d134..0f1ed68f9 100644 --- a/app/Models/FluidbookTranslate.php +++ b/app/Models/FluidbookTranslate.php @@ -11,6 +11,7 @@ use App\Models\Traits\FluidbookPlayerBranches; use Cubist\Backpack\Facades\App; use Cubist\Backpack\Magic\Models\Translate; use Cubist\Util\PHP; +use Illuminate\Support\Facades\Cache; // __('!!Traduction des fluidbooks') class FluidbookTranslate extends Translate @@ -75,35 +76,40 @@ class FluidbookTranslate extends Translate return resource_path('lang/fluidbook.' . $locale . '.json'); } - /** - * @throws \JsonException - */ - public static function getAllFluidbookTranslations() + public static function getAllFluidbookTranslations($force = false) { - start_measure('Get all fluidbook translations'); if (null === self::$_allTranslations) { - $t = FluidbookTranslate::find(1); - try { - $json = json_decode($t->getRawOriginal('content_translatable'), true, 512, JSON_THROW_ON_ERROR); - } catch (\Exception $e) { - $json = []; + $cacheKey = 'all_fluidbook_translations'; + if ($force) { + Cache::forget($cacheKey); } + self::$_allTranslations = Cache::remember($cacheKey, 3600, function () { + start_measure('Get all fluidbook translations !'); + $t = FluidbookTranslate::find(1); + try { + $json = json_decode($t->getRawOriginal('content_translatable'), true, 512, JSON_THROW_ON_ERROR); + } catch (\Exception $e) { + $json = []; + } - self::$_allTranslations = []; + $res = []; - foreach ($json as $code => $tr) { - $res[$code] = []; - foreach ($tr as $k => $v) { - self::$_allTranslations[$code][$k] = ['str' => self::keyToStr($k), 'translation' => $v]; + foreach ($json as $code => $tr) { + $res[$code] = []; + foreach ($tr as $k => $v) { + $res[$code][$k] = ['str' => self::keyToStr($k), 'translation' => $v]; + } } - } - $nsis = json_decode($t->getRawOriginal('nsis'), true, 512, JSON_THROW_ON_ERROR); - foreach ($nsis as $code => $v) { - self::$_allTranslations[$code]['nsis'] = $v; - } + $nsis = json_decode($t->getRawOriginal('nsis'), true, 512, JSON_THROW_ON_ERROR); + foreach ($nsis as $code => $v) { + $res[$code]['nsis'] = $v; + } + stop_measure('Get all fluidbook translations !'); + return $res; + + }); } - stop_measure('Get all fluidbook translations'); return self::$_allTranslations; } -- 2.39.5