Skip to content

Commit

Permalink
changed: make survey updates propagate much faster in offline-capable…
Browse files Browse the repository at this point in the history
… webforms,

closes kobotoolbox#156
  • Loading branch information
ivermac authored and MartijnR committed Feb 9, 2016
1 parent bd8ee4e commit e41d630
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http:https://semver.org/).

[Unreleased]
[1.23.1] - 2016-02-09
----------------------
##### Changed
- Make form updates propagate much faster in offline-capable views.

##### Fixed
- Min() and max() return undefined for empty values.
- Parallel batch uploads may cause lost data in ODK Aggregate.
Expand Down
16 changes: 9 additions & 7 deletions app/controllers/transformation-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ router
next();
} )
.post( '/xform', getSurveyParts )
.post( '/xform/hash', getCachedSurveyHash );
.post( '/xform/hash', getSurveyHash );

/**
* Obtains HTML Form, XML model, and existing XML instance
Expand Down Expand Up @@ -84,21 +84,22 @@ function getSurveyParts( req, res, next ) {
* @param {Function} next [description]
* @return {[type]} [description]
*/
function getCachedSurveyHash( req, res, next ) {
function getSurveyHash( req, res, next ) {
_getSurveyParams( req.body )
.then( function( survey ) {
return cacheModel.getHashes( survey );
} )
.then( function( survey ) {
delete survey.credentials;
return _updateCache( survey );
} )
.then( function( survey ) {
if ( survey.hasOwnProperty( 'credentials' ) ) {
delete survey.credentials;
}
res.status( 200 );
res.send( {
hash: _getCombinedHash( survey )
} );
// update cache if necessary, asynchronously AFTER responding
// this is the ONLY mechanism by which a locally browser-stored form
// will be updated
_updateCache( survey );
} )
.catch( next );
}
Expand Down Expand Up @@ -133,6 +134,7 @@ function _updateCache( survey ) {
return _getFormDirectly( survey )
.then( cacheModel.set );
}
return survey;
} )
.catch( function( error ) {
if ( error.status === 401 || error.status === 404 ) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "enketo-express",
"description": "A simplified version of Enketo Smart Paper that requires a constant connection to the server.",
"homepage": "",
"version": "1.23.0",
"version": "1.23.1",
"main": "./app.js",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion public/js/src/module/form-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function _setUpdateIntervals( survey ) {
// that open the form right after the XForm update.
setTimeout( function() {
_updateCache( survey );
}, 30 * 1000 );
}, 3 * 1000 );
// check for form update every 20 minutes
setInterval( function() {
_updateCache( survey );
Expand Down

0 comments on commit e41d630

Please sign in to comment.