From b6d8611359ed2cd701ee7997f095487c4bdcba92 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Fri, 25 Jan 2019 09:06:25 +0800 Subject: [PATCH] Return early in JS if last batch --- .../controllers/import_form_controller.js.coffee | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/admin/product_import/controllers/import_form_controller.js.coffee b/app/assets/javascripts/admin/product_import/controllers/import_form_controller.js.coffee index d1454307dc..174d0049d9 100644 --- a/app/assets/javascripts/admin/product_import/controllers/import_form_controller.js.coffee +++ b/app/assets/javascripts/admin/product_import/controllers/import_form_controller.js.coffee @@ -60,18 +60,20 @@ angular.module("admin.productImport").controller "ImportFormCtrl", ($scope, $htt $scope.processBatch = (step, batchIndex, batchCount) -> start = (batchIndex * $scope.batchSize) + 1 end = (batchIndex + 1) * $scope.batchSize - withNextBatch = batchIndex + 1 < batchCount + isLastBatch = batchCount == batchIndex + 1 promise = if step == 'import' $scope.processImport(start, end) else if step == 'save' $scope.processSave(start, end) + return if isLastBatch + processNextBatch = -> $scope.processBatch(step, batchIndex + 1, batchCount) # Process next batch whether or not processing of the current batch succeeds. - promise.then(processNextBatch, processNextBatch) if withNextBatch + promise.then(processNextBatch, processNextBatch) $scope.processImport = (start, end) -> $http(