Skip to content

Commit

Permalink
Merge pull request #609 from atton16/rk-unsw-patch-speed
Browse files Browse the repository at this point in the history
patch(survey): speedup server calls
  • Loading branch information
shankari authored Oct 28, 2019
2 parents ef1608d + a431f8d commit b875a74
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions www/js/diary/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -992,12 +992,24 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger',
var tripsFromServerPromise = timeline.updateFromServer(day);
var isProcessingCompletePromise = timeline.isProcessingComplete(day);

// Also mode/purpose and survey answers
var tq = $window.cordova.plugins.BEMUserCache.getAllTimeQuery();
var modesPromise = UnifiedDataLoader.getUnifiedMessagesForInterval('manual/mode_confirm', tq);
var purposesPromise = UnifiedDataLoader.getUnifiedMessagesForInterval('manual/purpose_confirm', tq);
var surveyAnswersPromise = EnketoSurvey.getAllSurveyAnswers("manual/confirm_survey", { populateLabels: true });

// Deal with all the trip retrieval
Promise.all([tripsFromServerPromise, isProcessingCompletePromise])
.then(function([processedTripList, completeStatus]) {
Promise.all([tripsFromServerPromise, isProcessingCompletePromise, modesPromise, purposesPromise, surveyAnswersPromise])
.then(function([processedTripList, completeStatus, modes, purposes, surveyAnswers]) {
console.log("Promise.all() finished successfully with length "
+processedTripList.length+" completeStatus = "+completeStatus);
console.log(` with ${modes.length} modes, ${purposes.length} purposes, ${surveyAnswers.length} surveyAnswers`);
var tripList = processedTripList;
timeline.data.unifiedConfirmsResults = {
modes: modes,
purposes: purposes,
surveyAnswers: surveyAnswers,
};
if (!completeStatus) {
return timeline.readUnprocessedTrips(day, processedTripList)
.then(function(unprocessedTripList) {
Expand All @@ -1010,20 +1022,6 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger',
} else {
return tripList;
}
}).then(function(combinedTripList) {
var tq = { key: 'write_ts', startTs: 0, endTs: moment().endOf('day').unix(), };
return Promise.all([
UnifiedDataLoader.getUnifiedMessagesForInterval('manual/mode_confirm', tq),
UnifiedDataLoader.getUnifiedMessagesForInterval('manual/purpose_confirm', tq),
EnketoSurvey.getAllSurveyAnswers("manual/confirm_survey", { populateLabels: true }),
]).then(function(results) {
timeline.data.unifiedConfirmsResults = {
modes: results[0],
purposes: results[1],
surveyAnswers: results[2],
};
return combinedTripList;
});
}).then(function(combinedTripList) {
processOrDisplayNone(day, combinedTripList);
}).catch(function(error) {
Expand Down

0 comments on commit b875a74

Please sign in to comment.