File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010use Illuminate \Queue \Middleware \WithoutOverlapping ;
1111use Illuminate \Support \Facades \Artisan ;
1212
13- class RefreshArtisanCaches implements ShouldQueue, ShouldBeUnique
13+ class RefreshArtisanCaches implements ShouldQueue
1414{
1515 use Dispatchable, InteractsWithQueue, Queueable;
1616
17- public $ tries = 2 ; // One extra try to handle the debounce release
18-
19- public $ queuedAt ;
20-
21- /**
22- * Create a new job instance.
23- *
24- * @return void
25- */
26- public function __construct ()
27- {
28- $ this ->queuedAt = time ();
29- }
30-
31- /**
32- * Debounce when multiple Settings are saved at the same time
33- *
34- * @return array<int, object>
35- */
36- public function middleware (): array
37- {
38- return [
39- (new WithoutOverlapping ('refresh_artisan_caches ' ))->dontRelease (),
40- ];
41- }
42-
4317 /**
4418 * Execute the job.
4519 *
@@ -54,13 +28,6 @@ public function handle()
5428 return ;
5529 }
5630
57- // Wait 3 seconds before running the job - debounce
58- if ($ this ->queuedAt && $ this ->queuedAt >= time () - 3 ) {
59- $ this ->release (3 );
60-
61- return ;
62- }
63-
6431 $ options = [
6532 '--no-interaction ' => true ,
6633 '--quiet ' => true ,
Original file line number Diff line number Diff line change 1010
1111class SettingObserver
1212{
13+ private static $ added_refresh_artisan_caches = false ;
14+
1315 /**
1416 * Handle the setting "created" event.
1517 *
@@ -91,6 +93,19 @@ private function invalidateSettingCache(Setting $setting)
9193 $ key = $ settingCache ->createKey (['key ' => $ setting ->key ]);
9294 $ settingCache ->invalidate (['key ' => $ key ]);
9395
94- RefreshArtisanCaches::dispatch ();
96+ // Check to see if we already added the refresh to the app's terminating queue.
97+ // This is important for install commands when multiple settings are being created/updated.
98+ if (self ::$ added_refresh_artisan_caches ) {
99+ return ;
100+ }
101+
102+ // Use app()->terminating to ensure the cache is refreshed after the settings have been saved.
103+ app ()->terminating (function () {
104+ // Do this synchronously so we dont have to wait after settings have been saved.
105+ // This command runs pretty fast and only when an admin is updating settings.
106+ RefreshArtisanCaches::dispatchSync ();
107+ });
108+
109+ self ::$ added_refresh_artisan_caches = true ;
95110 }
96111}
You can’t perform that action at this time.
0 commit comments