@@ -162,6 +162,8 @@ private function importCalculators(string $filepath, int $barId): void
162162
163163 private function importIngredients (Filesystem $ dataDisk , Bar $ bar , User $ user ): void
164164 {
165+ $ timerStart = microtime (true );
166+
165167 $ existingIngredients = DB ::table ('ingredients ' )->select ('id ' , 'name ' )->where ('bar_id ' , $ bar ->id )->get ()->keyBy (function ($ ingredient ) {
166168 return Str::slug ($ ingredient ->name );
167169 });
@@ -173,6 +175,7 @@ private function importIngredients(Filesystem $dataDisk, Bar $bar, User $user):
173175 $ barImagesDir = $ bar ->getIngredientsDirectory ();
174176 $ this ->uploadsDisk ->makeDirectory ($ barImagesDir );
175177
178+ $ imagesTimer = 0.0 ;
176179 foreach ($ this ->getDataFromDir ('ingredients ' , $ dataDisk ) as $ fromYield ) {
177180 [$ externalIngredient , $ filePath ] = $ fromYield ;
178181 $ externalIngredient = IngredientExternal::fromDataPackArray ($ externalIngredient );
@@ -208,6 +211,7 @@ private function importIngredients(Filesystem $dataDisk, Bar $bar, User $user):
208211 }
209212
210213 // For performance, manually copy the files and create image references
214+ $ imagesTimerStart = microtime (true );
211215 foreach ($ externalIngredient ->images as $ image ) {
212216 $ baseSrcImagePath = $ filePath . $ image ->getLocalFilePath ();
213217 $ fileExtension = File::extension ($ dataDisk ->path ($ baseSrcImagePath ));
@@ -226,8 +230,12 @@ private function importIngredients(Filesystem $dataDisk, Bar $bar, User $user):
226230 'updated_at ' => null ,
227231 ];
228232 }
233+ $ imageTimerEnd = microtime (true );
234+ $ imagesTimer += ($ imageTimerEnd - $ imagesTimerStart );
229235 }
230236
237+ Log::debug (sprintf ('Ingredient image copy completed in %d ms ' , $ imagesTimer * 1000 ));
238+
231239 // Start inserting
232240 DB ::beginTransaction ();
233241
@@ -280,10 +288,15 @@ private function importIngredients(Filesystem $dataDisk, Bar $bar, User $user):
280288 DB ::commit ();
281289
282290 $ this ->ingredientRepository ->rebuildMaterializedPath ($ bar ->id );
291+
292+ $ timerEnd = microtime (true );
293+ Log::debug (sprintf ('Ingredients import completed in %d ms ' , ($ timerEnd - $ timerStart ) * 1000 ));
283294 }
284295
285296 private function importBaseCocktails (Filesystem $ dataDisk , Bar $ bar , User $ user ): void
286297 {
298+ $ timerStart = microtime (true );
299+
287300 $ dbIngredients = DB ::table ('ingredients ' )->select ('id ' , DB ::raw ('LOWER(name) AS name ' ))->where ('bar_id ' , $ bar ->id )->get ()->keyBy ('name ' )->map (fn ($ row ) => $ row ->id )->toArray ();
288301 $ dbGlasses = DB ::table ('glasses ' )->select ('id ' , DB ::raw ('LOWER(name) AS name ' ))->where ('bar_id ' , $ bar ->id )->get ()->keyBy ('name ' )->map (fn ($ row ) => $ row ->id )->toArray ();
289302 $ dbMethods = DB ::table ('cocktail_methods ' )->select ('id ' , DB ::raw ('LOWER(name) AS name ' ))->where ('bar_id ' , $ bar ->id )->get ()->keyBy ('name ' )->map (fn ($ row ) => $ row ->id )->toArray ();
@@ -302,6 +315,7 @@ private function importBaseCocktails(Filesystem $dataDisk, Bar $bar, User $user)
302315 $ barImagesDir = 'cocktails/ ' . $ bar ->id . '/ ' ;
303316 $ this ->uploadsDisk ->makeDirectory ($ barImagesDir );
304317
318+ $ imagesTimer = 0.0 ;
305319 foreach ($ this ->getDataFromDir ('cocktails ' , $ dataDisk ) as $ fromYield ) {
306320 [$ cocktail , $ filePath ] = $ fromYield ;
307321
@@ -385,6 +399,7 @@ private function importBaseCocktails(Filesystem $dataDisk, Bar $bar, User $user)
385399 }
386400
387401 // For performance, manually copy the files and create image references
402+ $ imagesTimerStart = microtime (true );
388403 foreach ($ externalCocktail ->images as $ image ) {
389404 $ baseSrcImagePath = $ filePath . $ image ->getLocalFilePath ();
390405 $ fileExtension = File::extension ($ dataDisk ->path ($ baseSrcImagePath ));
@@ -404,8 +419,12 @@ private function importBaseCocktails(Filesystem $dataDisk, Bar $bar, User $user)
404419 'updated_at ' => null ,
405420 ];
406421 }
422+ $ imageTimerEnd = microtime (true );
423+ $ imagesTimer += ($ imageTimerEnd - $ imagesTimerStart );
407424 }
408425
426+ Log::debug (sprintf ('Cocktail image copy completed in %d ms ' , $ imagesTimer * 1000 ));
427+
409428 DB ::beginTransaction ();
410429
411430 $ tagsToInsert = [];
@@ -496,6 +515,9 @@ private function importBaseCocktails(Filesystem $dataDisk, Bar $bar, User $user)
496515 DB ::table ('images ' )->insert ($ imagesToInsert );
497516
498517 DB ::commit ();
518+
519+ $ timerEnd = microtime (true );
520+ Log::debug (sprintf ('Cocktails import completed in %d ms ' , ($ timerEnd - $ timerStart ) * 1000 ));
499521 }
500522
501523 private function copyResourceImage (Filesystem $ dataDisk , string $ baseSrcImagePath , string $ targetImagePath ): void
0 commit comments