From a0eb6c95969fe0f45f01600134556ed002949dee Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 14 Dec 2023 11:02:39 +0100 Subject: [PATCH] wip #6433 @2 --- .docker/config/php/fpm.conf | 6 ++-- app/Jobs/UpdateWS2ThemeTable.php | 60 ++++++++++++++++++-------------- app/Models/FluidbookTheme.php | 21 +++++------ scripts/fixrights.sh | 1 + 4 files changed, 45 insertions(+), 43 deletions(-) diff --git a/.docker/config/php/fpm.conf b/.docker/config/php/fpm.conf index 710dfd9e8..9cc8b92d4 100644 --- a/.docker/config/php/fpm.conf +++ b/.docker/config/php/fpm.conf @@ -31,7 +31,7 @@ group = 33 pm = dynamic pm.max_children = 320 -pm.start_servers = 96 -pm.min_spare_servers = 80 -pm.max_spare_servers = 160 +pm.start_servers = 180 +pm.min_spare_servers = 160 +pm.max_spare_servers = 240 pm.max_requests = 1000 diff --git a/app/Jobs/UpdateWS2ThemeTable.php b/app/Jobs/UpdateWS2ThemeTable.php index a38a97e7a..d6d48d15a 100644 --- a/app/Jobs/UpdateWS2ThemeTable.php +++ b/app/Jobs/UpdateWS2ThemeTable.php @@ -10,6 +10,8 @@ use Cubist\Backpack\Magic\Fields\Files; use Cubist\Util\CommandLine\Imagemagick; use Cubist\Util\Graphics\Image; use Fluidbook\Tools\SVG\SVGTools; +use Illuminate\Database\UniqueConstraintViolationException; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; use Mockery\Exception; use Spatie\MediaLibrary\MediaCollections\Models\Media; @@ -45,39 +47,43 @@ class UpdateWS2ThemeTable extends Base */ public function handle() { - $theme = new FluidbookTheme(); - - foreach ($theme->getFields() as $field) { - $name = $field->getAttribute('name'); - $this->_allFields[] = $name; - if ($field instanceof Files) { - $this->_fileFields[] = $name; - } else if ($field instanceof Color) { - if ($field->getAttribute('allows_alpha')) { - $this->_colorAlphaFields[] = $name; - } else { - $this->_colorFields[] = $name; + $lock = Cache::lock('job_' . $this->uniqueId(), 10); + if ($lock->get()) { + $theme = new FluidbookTheme(); + + foreach ($theme->getFields() as $field) { + $name = $field->getAttribute('name'); + $this->_allFields[] = $name; + if ($field instanceof Files) { + $this->_fileFields[] = $name; + } else if ($field instanceof Color) { + if ($field->getAttribute('allows_alpha')) { + $this->_colorAlphaFields[] = $name; + } else { + $this->_colorFields[] = $name; + } } } - } - $this->_ignore = ['id', 'name', 'owner', 'created_at', 'deleted_at', 'updated_at', 'slug', 'signature']; + $this->_ignore = ['id', 'name', 'owner', 'created_at', 'deleted_at', 'updated_at', 'slug', 'signature']; - $data = []; - $t = DB::table('extranet_clean.ws3_themes'); - if ($this->id === 'all') { - foreach (FluidbookTheme::where('created_ok', 1)->get() as $theme) { + $data = []; + $t = DB::table('extranet_clean.ws3_themes'); + if ($this->id === 'all') { + foreach (FluidbookTheme::where('created_ok', 1)->get() as $theme) { + $data[] = $this->_handleTheme($theme); + } + $t->truncate(); + } else { + $theme = FluidbookTheme::find($this->id); $data[] = $this->_handleTheme($theme); + $t->where('theme_id', '=', $this->id)->delete(); } - $t->truncate(); - } else { - $theme = FluidbookTheme::find($this->id); - $data[] = $this->_handleTheme($theme); - $t->where('theme_id', '=', $this->id)->delete(); - } - try { - $t->insert($data); - } catch (Exception $e) { + try { + $t->insert($data); + } catch (Exception|UniqueConstraintViolationException $e) { + } + $lock->release(); } } diff --git a/app/Models/FluidbookTheme.php b/app/Models/FluidbookTheme.php index 9c9d7a97c..395201f22 100644 --- a/app/Models/FluidbookTheme.php +++ b/app/Models/FluidbookTheme.php @@ -672,11 +672,12 @@ class FluidbookTheme extends ToolboxModel return self::$_colorToWS3Cache[$data]; } - public function postSave() + public function onSaved(): bool { - parent::postSave(); + $res = parent::onSaved(); self::updateWS2Table($this->id); $this->_generateThemePreview(); + return $res; } protected function _generateThemePreview($sync = false) @@ -684,25 +685,19 @@ class FluidbookTheme extends ToolboxModel dispatch(new GenerateThemePreview($this))->onQueue('theme'); } - public function postCreate() - { - parent::postCreate(); - self::updateWS2Table($this->id); - $this->_generateThemePreview(); - } - - public function postDelete() + public function onDeleted(): bool { - parent::postDelete(); + $res = parent::onDeleted(); self::updateWS2Table(); + return $res; } public static function updateWS2Table($id = null) { + if (self::$updateWS2ViewOnChange) { if (null !== $id) { - $job = new UpdateWS2ThemeTable($id); - dispatch_sync($job); + dispatch_sync(new UpdateWS2ThemeTable($id)); } dispatch(new UpdateWS2ThemeTable('all'))->onQueue('theme'); } diff --git a/scripts/fixrights.sh b/scripts/fixrights.sh index 33e1e5cea..4d1ecece7 100644 --- a/scripts/fixrights.sh +++ b/scripts/fixrights.sh @@ -1,5 +1,6 @@ #!/bin/sh chown root:root /home/toolbox/www/.docker/config/sudoers +chown root:root /home/toolbox/www/.docker/config/cron/host chmod -R 755 /home/toolbox/www/scripts chmod -R 775 /home/toolbox/www/protected chmod -R 775 /home/toolbox/www/public -- 2.39.5