I am building an app with angular and node js. I have a very big query (insert query) that inserts something like 30,000 rows which for some reason takes a few minutes (i suppose its ok).
this is my query:
this.createCourts = function (req, res, next){
console.log("entered creation courts");
connection.query('CALL filldates("' +
req.body['startDate'] + '","' +
req.body['endDate'] + '","' +
req.body['numOfCourts'] + '","' +
req.body['duration'] + '","' +
req.body['sundayOpen'] + '","' +
req.body['mondayOpen'] + '","' +
req.body['tuesdayOpen'] + '","' +
req.body['wednesdayOpen'] + '","' +
req.body['thursdayOpen'] + '","' +
req.body['fridayOpen'] + '","' +
req.body['saturdayOpen'] + '","' +
req.body['sundayClose'] + '","' +
req.body['mondayClose'] + '","' +
req.body['tuesdayClose'] + '","' +
req.body['wednesdayClose'] + '","' +
req.body['thursdayClose'] + '","' +
req.body['fridayClose'] + '","' +
req.body['saturdayClose'] +
'");', function(err, result, fields){
if (err){
console.log("error is" + err);
return res.send(500, "fail");
}
else{
console.log("finsihed");
return res.send(200);
}
});
});
};
my ui will click a button which will trigger a service like this:
CourtsService.createCourts.save({},
{"startDate": dateService.Date_toYMD($scope.startDate),
"endDate": dateService.Date_toYMD($scope.endDate),
"numOfCourts": $scope.numOfCourts,
"duration": $scope.duration,
"sundayOpen": $scope.sundayOpen.hour,
"mondayOpen": $scope.mondayOpen.hour,
"tuesdayOpen": $scope.tuesdayOpen.hour,
"wednesdayOpen": $scope.wednesdayOpen.hour,
"thursdayOpen": $scope.thursdayOpen.hour,
"fridayOpen": $scope.fridayOpen.hour,
"saturdayOpen": $scope.saturdayOpen.hour,
"sundayClose": $scope.sundayClose.hour,
"mondayClose": $scope.mondayClose.hour,
"tuesdayClose": $scope.tuesdayClose.hour,
"wednesdayClose": $scope.wednesdayClose.hour,
"thursdayClose": $scope.thursdayClose.hour,
"fridayClose": $scope.fridayClose.hour,
"saturdayClose": $scope.saturdayClose.hour},
function(data){
$scope.showSearching = false;
$dialog.messageBox("success", btns).open();
}, function(err){
$scope.showSearching = false;
$dialog.messageBox("fail", err.data, btns).open();
});
I added this row on the first line of the function that will actually do the query(its in the code up here) console.log("entered creation courts");
My problem is that because the query runs for a few minutes (may be 10 minutes), it seems as if my function is being called again and again because I can see in my console the line "entered creation courts" approximately every 1 minute and this is ofcourse not something i wish to be happening.
I don't know what triggers the createCourts function again and again.
maybe it is because the UI goes into time out and thus triggers the service again if an answer hasn't been received after 1 minutes (or something close to that). and if this is the reason how do I tell the service to just wait for an answer?