Project:
View Issue Details[ Jump to Notes ] | [ Issue History ] [ Print ] | |||||||
ID | ||||||||
0041027 | ||||||||
Type | Category | Severity | Reproducibility | Date Submitted | Last Update | |||
feature request | [Retail Modules] Web POS | major | N/A | 2019-06-04 18:50 | 2019-11-04 11:22 | |||
Reporter | gorka_gil | View Status | public | |||||
Assigned To | gorka_gil | |||||||
Priority | normal | Resolution | fixed | Fixed in Version | RR19Q4 | |||
Status | closed | Fix in branch | Fixed in SCM revision | 86b8435e3609 | ||||
Projection | none | ETA | none | Target Version | ||||
OS | Any | Database | Any | Java version | ||||
OS Version | Database version | Ant version | ||||||
Product Version | SCM revision | |||||||
Review Assigned To | marvintm | |||||||
Regression level | ||||||||
Regression date | ||||||||
Regression introduced in release | ||||||||
Regression introduced by commit | ||||||||
Triggers an Emergency Pack | No | |||||||
Summary | 0041027: Optimize masterdata incremental refresh process | |||||||
Description | Current masterdata incremental refresh process, blocks the ui during the process that takes some seconds. The current process is: - block ui with a show loading - request one mastertdata model and insert into the db - continue in the same way with the rest of models one by one | |||||||
Steps To Reproduce | - | |||||||
Proposed Solution | The proposal is: - request all the models in background, without block the ui, saving in the ram - when all data ready, block the ui and save into db Since the amount of data can be very big for the ram, idea is to try in this way, but once passed a limit, go back to the current incremental refresh | |||||||
Tags | No tags attached. | |||||||
Attached Files | 41027-incrementalRefresh-mobilecore-18q3-newFormatter.diff [^] (26,751 bytes) 2019-08-27 11:29 [Show Content] [Hide Content]diff -r fc8eea1df2d4 -r dcdaa8c28650 src-db/database/sourcedata/AD_MESSAGE.xml --- a/src-db/database/sourcedata/AD_MESSAGE.xml Mon Aug 26 12:05:12 2019 +0200 +++ b/src-db/database/sourcedata/AD_MESSAGE.xml Wed Jul 31 17:55:38 2019 +0200 @@ -1876,6 +1876,18 @@ <!--C4E1B578B13840ADA3BC8092798E743A--> <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N> <!--C4E1B578B13840ADA3BC8092798E743A--></AD_MESSAGE> +<!--C768AEA530B44845ACBDA07AA15CF291--><AD_MESSAGE> +<!--C768AEA530B44845ACBDA07AA15CF291--> <AD_MESSAGE_ID><![CDATA[C768AEA530B44845ACBDA07AA15CF291]]></AD_MESSAGE_ID> +<!--C768AEA530B44845ACBDA07AA15CF291--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> +<!--C768AEA530B44845ACBDA07AA15CF291--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID> +<!--C768AEA530B44845ACBDA07AA15CF291--> <ISACTIVE><![CDATA[Y]]></ISACTIVE> +<!--C768AEA530B44845ACBDA07AA15CF291--> <VALUE><![CDATA[OBMOBC_MasterdataRequestError]]></VALUE> +<!--C768AEA530B44845ACBDA07AA15CF291--> <MSGTEXT><![CDATA[There was an error in the masterdata requests, aborted current refresh]]></MSGTEXT> +<!--C768AEA530B44845ACBDA07AA15CF291--> <MSGTYPE><![CDATA[W]]></MSGTYPE> +<!--C768AEA530B44845ACBDA07AA15CF291--> <AD_MODULE_ID><![CDATA[08943B85ADF64E708797A753E5B6AAEE]]></AD_MODULE_ID> +<!--C768AEA530B44845ACBDA07AA15CF291--> <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N> +<!--C768AEA530B44845ACBDA07AA15CF291--></AD_MESSAGE> + <!--C88B6F2C58B3477BAEA816BF54559E50--><AD_MESSAGE> <!--C88B6F2C58B3477BAEA816BF54559E50--> <AD_MESSAGE_ID><![CDATA[C88B6F2C58B3477BAEA816BF54559E50]]></AD_MESSAGE_ID> <!--C88B6F2C58B3477BAEA816BF54559E50--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> diff -r fc8eea1df2d4 -r dcdaa8c28650 src-db/database/sourcedata/AD_PREFERENCE.xml --- a/src-db/database/sourcedata/AD_PREFERENCE.xml Mon Aug 26 12:05:12 2019 +0200 +++ b/src-db/database/sourcedata/AD_PREFERENCE.xml Wed Jul 31 17:55:38 2019 +0200 @@ -22,6 +22,17 @@ <!--01EAFAD3A2204971A35D18E8CEBE9F8C--> <AD_MODULE_ID><![CDATA[08943B85ADF64E708797A753E5B6AAEE]]></AD_MODULE_ID> <!--01EAFAD3A2204971A35D18E8CEBE9F8C--></AD_PREFERENCE> +<!--0280B1B0ED464B34924688C1C678A52A--><AD_PREFERENCE> +<!--0280B1B0ED464B34924688C1C678A52A--> <AD_PREFERENCE_ID><![CDATA[0280B1B0ED464B34924688C1C678A52A]]></AD_PREFERENCE_ID> +<!--0280B1B0ED464B34924688C1C678A52A--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> +<!--0280B1B0ED464B34924688C1C678A52A--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID> +<!--0280B1B0ED464B34924688C1C678A52A--> <ISACTIVE><![CDATA[Y]]></ISACTIVE> +<!--0280B1B0ED464B34924688C1C678A52A--> <VALUE><![CDATA[Y]]></VALUE> +<!--0280B1B0ED464B34924688C1C678A52A--> <PROPERTY><![CDATA[OBMOBC_NotAutoLoadIncrementalAtLogin]]></PROPERTY> +<!--0280B1B0ED464B34924688C1C678A52A--> <ISPROPERTYLIST><![CDATA[Y]]></ISPROPERTYLIST> +<!--0280B1B0ED464B34924688C1C678A52A--> <AD_MODULE_ID><![CDATA[08943B85ADF64E708797A753E5B6AAEE]]></AD_MODULE_ID> +<!--0280B1B0ED464B34924688C1C678A52A--></AD_PREFERENCE> + <!--18639B6C06B44324A65D199CD8A32440--><AD_PREFERENCE> <!--18639B6C06B44324A65D199CD8A32440--> <AD_PREFERENCE_ID><![CDATA[18639B6C06B44324A65D199CD8A32440]]></AD_PREFERENCE_ID> <!--18639B6C06B44324A65D199CD8A32440--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> diff -r fc8eea1df2d4 -r dcdaa8c28650 src-db/database/sourcedata/AD_REF_LIST.xml --- a/src-db/database/sourcedata/AD_REF_LIST.xml Mon Aug 26 12:05:12 2019 +0200 +++ b/src-db/database/sourcedata/AD_REF_LIST.xml Wed Jul 31 17:55:38 2019 +0200 @@ -307,6 +307,18 @@ <!--645E9EE10111462CB8C4E6B9E504CEA3--> <AD_MODULE_ID><![CDATA[08943B85ADF64E708797A753E5B6AAEE]]></AD_MODULE_ID> <!--645E9EE10111462CB8C4E6B9E504CEA3--></AD_REF_LIST> +<!--6E6E9B37800B4F50AAAD606330E887C3--><AD_REF_LIST> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <AD_REF_LIST_ID><![CDATA[6E6E9B37800B4F50AAAD606330E887C3]]></AD_REF_LIST_ID> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <ISACTIVE><![CDATA[Y]]></ISACTIVE> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <VALUE><![CDATA[OBMOBC_BackgroundMasterdataMaxSize]]></VALUE> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <NAME><![CDATA[Background Masterdata Maximum Size]]></NAME> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <DESCRIPTION><![CDATA[Maximum size for all models for incremental masterdata refresh in background. Value -1 disable the background refresh of the masterdata]]></DESCRIPTION> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <AD_REFERENCE_ID><![CDATA[A26BA480E2014707B47257024C3CBFF7]]></AD_REFERENCE_ID> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <AD_MODULE_ID><![CDATA[08943B85ADF64E708797A753E5B6AAEE]]></AD_MODULE_ID> +<!--6E6E9B37800B4F50AAAD606330E887C3--></AD_REF_LIST> + <!--73967117B13C4B5EAEA505E04A7E80A3--><AD_REF_LIST> <!--73967117B13C4B5EAEA505E04A7E80A3--> <AD_REF_LIST_ID><![CDATA[73967117B13C4B5EAEA505E04A7E80A3]]></AD_REF_LIST_ID> <!--73967117B13C4B5EAEA505E04A7E80A3--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> diff -r fc8eea1df2d4 -r dcdaa8c28650 web/org.openbravo.mobile.core/source/data/ob-dal.js --- a/web/org.openbravo.mobile.core/source/data/ob-dal.js Mon Aug 26 12:05:12 2019 +0200 +++ b/web/org.openbravo.mobile.core/source/data/ob-dal.js Wed Jul 31 17:55:38 2019 +0200 @@ -2164,7 +2164,14 @@ * * */ - OB.Dal.loadModels = function(online, models, data, incremental, callback) { + OB.Dal.loadModels = function( + online, + models, + data, + incremental, + callback, + background + ) { var timestamp = 0; var key; @@ -2209,6 +2216,7 @@ // We can safely set the POSLastIncRefresh timestamp now. OB.UTIL.localStorage.setItem("POSLastIncRefresh", new Date().getTime()); dalLoadModelsCallback(); + return; } if ( OB.MobileApp.model.get("modelsToLoad").length === 0 && @@ -2436,36 +2444,40 @@ } } }; - OB.Data.localDB.transaction( - function(tx) { - tx.executeSql( - "select count(1) as totalRecords from " + - item.prototype.tableName, - [], - function(tx, result) { - logMsgForTransaction( - true, - item.prototype.modelName, - result.rows.item(0).totalRecords - ); - checkRecordsWithBackend( - item.prototype.modelName, - result.rows.item(0).totalRecords - ); - }, - function() { - logMsgForTransaction(false, item.prototype.modelName); - } - ); - }, - function(errorMsg) { - OB.error(errorMsg); - finishTransaction(); - }, - function() { - finishTransaction(); - } - ); + if (incremental) { + finishTransaction(); + } else { + OB.Data.localDB.transaction( + function(tx) { + tx.executeSql( + 'select count(1) as totalRecords from ' + + item.prototype.tableName, + [], + function(tx, result) { + logMsgForTransaction( + true, + item.prototype.modelName, + result.rows.item(0).totalRecords + ); + checkRecordsWithBackend( + item.prototype.modelName, + result.rows.item(0).totalRecords + ); + }, + function() { + logMsgForTransaction(false, item.prototype.modelName); + } + ); + }, + function(errorMsg) { + OB.error(errorMsg); + finishTransaction(); + }, + function() { + finishTransaction(); + } + ); + } } // Skip load of models if it's a incremental refresh and the request timeout has been reached @@ -2481,7 +2493,7 @@ item.params.terminalTime = currentDate; item.params.terminalTimeOffset = currentDate.getTimezoneOffset(); } - ds.load(item.params, incremental); + ds.load(item.params, incremental, background); } } else if ( item && diff -r fc8eea1df2d4 -r dcdaa8c28650 web/org.openbravo.mobile.core/source/data/ob-datasource.js --- a/web/org.openbravo.mobile.core/source/data/ob-datasource.js Mon Aug 26 12:05:12 2019 +0200 +++ b/web/org.openbravo.mobile.core/source/data/ob-datasource.js Wed Jul 31 17:55:38 2019 +0200 @@ -20,6 +20,8 @@ OB.DS.requestAllowed = isAllowed; }; + OB.DS.masterdataBackgroundModels = {}; // To store the models loaded in the masterdata refresh done in background + function serviceSuccess(inSender, inResponse, callback, tx) { if (inResponse._entityname) { callback([inResponse]); @@ -616,15 +618,8 @@ }; _.extend(OB.DS.DataSource.prototype, Backbone.Events); - OB.DS.DataSource.prototype.load = function(params, incremental) { + OB.DS.DataSource.prototype.load = function(params, incremental, background) { this.modelPagination = 1; - OB.info( - "[sdreresh-" + - (incremental ? "inc" : "full") + - "] The model " + - this.request.model.prototype.modelName + - " has started masterdata load" - ); var me = this, handleError, handleIncrementalRequest, @@ -644,29 +639,67 @@ me.trigger("ready", "failed"); }; - handleIncrementalRequest = function( - limit, - offset, - params, - incremental, - lastId + + const updateModelLastUpdatedTimestamp = function( + lastUpdated, + data, + totalRows ) { - params = params || {}; - params._limit = limit; - params._offset = offset; - params._count = OB.UTIL.localStorage.getItem( - "recordsFromBackendFor" + me.request.model.prototype.modelName - ) - ? parseInt( + if (lastUpdated && data.length > 0) { + if ( + OB.UTIL.localStorage.getItem( + 'requestTimestamp' + me.request.model.prototype.modelName + ) && + OB.UTIL.localStorage.getItem( + 'requestTimestamp' + me.request.model.prototype.modelName + ) !== 'null' + ) { + OB.UTIL.localStorage.setItem( + 'lastUpdatedTimestamp' + me.request.model.prototype.modelName, OB.UTIL.localStorage.getItem( - "recordsFromBackendFor" + me.request.model.prototype.modelName - ), - 10 - ) - : 0; - params._isMasterdata = true; - params.overrideDefaultTimeout = true; - params.lastId = lastId; + 'requestTimestamp' + me.request.model.prototype.modelName + ) + ); + } else { + OB.error( + '[lastUpdatedTimestamp] ' + + 'local storage (lastUpdatedTimestamp' + + me.request.model.prototype.modelName + + ') attempted to be set as null. Ignored. Current Value: ' + + OB.UTIL.localStorage.getItem( + 'lastUpdatedTimestamp' + me.request.model.prototype.modelName + ) + ); + } + OB.UTIL.localStorage.removeItem( + 'requestTimestamp' + me.request.model.prototype.modelName + ); + OB.UTIL.localStorage.setItem( + 'recordsFromBackendFor' + me.request.model.prototype.modelName, + totalRows + ); + } else { + if ( + OB.UTIL.localStorage.getItem( + 'requestTimestamp' + me.request.model.prototype.modelName + ) && + OB.UTIL.localStorage.getItem( + 'requestTimestamp' + me.request.model.prototype.modelName + ) !== 'null' + ) { + OB.UTIL.localStorage.setItem( + 'lastUpdatedTimestamp' + me.request.model.prototype.modelName, + OB.UTIL.localStorage.getItem( + 'requestTimestamp' + me.request.model.prototype.modelName + ) + ); + } + } + }; + + const doModelRequest = function(params, functionSave, errorCallback) { + var offset = params._offset; + var limit = params._limit; if (offset === 0) { OB.UTIL.localStorage.setItem( "requestTimestamp" + me.request.model.prototype.modelName, @@ -685,6 +718,10 @@ ]) ); } + delete params._data; + delete params._model; + delete params._lastUpdated; + delete params._totalRows; me.request.exec( params, function(data, message, lastUpdated, totalRows) { @@ -726,7 +763,8 @@ offset + limit, params, incremental, - newLastId + newLastId, + background ); } else { OB.UTIL.completeLoadingStep(); @@ -744,106 +782,44 @@ " records in the pagination " + me.modelPagination ); - OB.info( - "[sdreresh-" + - (incremental ? "inc" : "full") + - "] The model " + - me.request.model.prototype.modelName + - " has finished loading with a total of " + - dataLoaded + - " records. " + - (me.modelPagination === 1 - ? "There was no pagination." - : "The number of paginations created were " + - me.modelPagination) - ); - if (lastUpdated && data.length > 0) { - if ( - OB.UTIL.localStorage.getItem( - "requestTimestamp" + me.request.model.prototype.modelName - ) && - OB.UTIL.localStorage.getItem( - "requestTimestamp" + me.request.model.prototype.modelName - ) !== "null" - ) { - OB.UTIL.localStorage.setItem( - "lastUpdatedTimestamp" + - me.request.model.prototype.modelName, - OB.UTIL.localStorage.getItem( - "requestTimestamp" + me.request.model.prototype.modelName - ) - ); - } else { - OB.error( - "[lastUpdatedTimestamp] " + - "local storage (lastUpdatedTimestamp" + - me.request.model.prototype.modelName + - ") attempted to be set as null. Ignored. Current Value: " + - OB.UTIL.localStorage.getItem( - "lastUpdatedTimestamp" + - me.request.model.prototype.modelName - ) - ); - } - OB.UTIL.localStorage.removeItem( - "requestTimestamp" + me.request.model.prototype.modelName + if (dataLoaded > 0) { + OB.info( + '[sdreresh-' + + (incremental ? 'inc' : 'full') + + '] The model ' + + me.request.model.prototype.modelName + + ' has finished loading with a total of ' + + dataLoaded + + ' records. ' + + (me.modelPagination === 1 + ? 'There was no pagination.' + : 'The number of paginations created were ' + + me.modelPagination) ); - OB.UTIL.localStorage.setItem( - "recordsFromBackendFor" + - me.request.model.prototype.modelName, - totalRows - ); - } else { - if ( - OB.UTIL.localStorage.getItem( - "requestTimestamp" + me.request.model.prototype.modelName - ) && - OB.UTIL.localStorage.getItem( - "requestTimestamp" + me.request.model.prototype.modelName - ) !== "null" - ) { - OB.UTIL.localStorage.setItem( - "lastUpdatedTimestamp" + - me.request.model.prototype.modelName, - OB.UTIL.localStorage.getItem( - "requestTimestamp" + me.request.model.prototype.modelName - ) - ); - } } + + if (background === undefined) { + updateModelLastUpdatedTimestamp(lastUpdated, data, totalRows); + } + me.trigger("ready"); } } if (data.exception) { OB.error("Error in datasource: " + data.exception); + OB.DS.masterdataBackgroundModels = {}; me.trigger("ready", "failed"); return; } if (me.request.model && me.request.model.prototype.online) { me.cache = me.cache ? me.cache.concat(data) : data; } - if (me.request.model && !me.request.model.prototype.online) { - if (offset === 0) { - OB.Dal.initCache( - me.request.model, - data, - success, - handleError, - incremental - ); - } else { - OB.Dal.insertData( - me.request.model, - data, - success, - handleError, - incremental, - dataLoaded - ); - } - } else { - success(); - } + + params._data = data; + params._model = me.request.model; + params._lastUpdated = lastUpdated; + params._totalRows = totalRows; + functionSave(params, success, errorCallback); }, function(data) { OB.UTIL.Debug.execute(function() { @@ -854,6 +830,14 @@ return; } }); + OB.DS.masterdataBackgroundModels = {}; + + OB.info( + OB.I18N.getLabel('OBMOBC_MasterdataRequestError') + + '. URL which failed: ' + + me.request.source + ); + OB.UTIL.showI18NWarning('OBMOBC_MasterdataRequestError'); if ( data && data.exception && @@ -876,6 +860,172 @@ ); }; + const doModelDataSave = function(params, success, handleError) { + const offset = params._offset; + const data = params._data; + const model = params._model; + if (model && !model.prototype.online) { + if (offset === 0) { + OB.Dal.initCache(model, data, success, handleError, incremental); + } else { + OB.Dal.insertData( + model, + data, + success, + handleError, + incremental, + dataLoaded + ); + } + } else { + success(); + } + }; + + const doModelDataSaveInRAM = function(params, success, handleError) { + const data = params._data; + const limit = params._limit; + const currentLength = data.length; + const backgroundLimit = OB.MobileApp.model.hasPermission( + 'OBMOBC_BackgroundMasterdataMaxSize', + true + ) + ? OB.MobileApp.model.hasPermission( + 'OBMOBC_BackgroundMasterdataMaxSize', + true + ) + : limit; + if ( + OB.DS.masterdataBackgroundModels['totalLength'] + currentLength > + backgroundLimit + ) { + OB.info( + 'Failed to do masterdata refresh in background because exceeds the limit of data. Trying normal refresh.' + ); + OB.UTIL.localStorage.setItem('neededForeGroundMasterDataRefresh'); + OB.UTIL.refreshMasterDataForeground(); + OB.DS.masterdataBackgroundModels = {}; + return; + } + if (!OB.DS.masterdataBackgroundModels.hasOwnProperty(me.request.source)) { + OB.DS.masterdataBackgroundModels[me.request.source] = {}; + OB.DS.masterdataBackgroundModels[me.request.source]['data'] = []; + } + + OB.DS.masterdataBackgroundModels[me.request.source]['data'] = [ + ...OB.DS.masterdataBackgroundModels[me.request.source]['data'], + ...params._data + ]; + + OB.DS.masterdataBackgroundModels[me.request.source]['model'] = + params._model; + OB.DS.masterdataBackgroundModels[me.request.source]['lastUpdated'] = + params._lastUpdated; + OB.DS.masterdataBackgroundModels[me.request.source]['totalRows'] = + params._totalRows; + + OB.DS.masterdataBackgroundModels[me.request.source]['lastUpdated'] = + me.request.lastUpdated; + + if (!OB.DS.masterdataBackgroundModels.hasOwnProperty('totalLength')) { + OB.DS.masterdataBackgroundModels['totalLength'] = 0; + } + OB.DS.masterdataBackgroundModels['totalLength'] += currentLength; + success(); + }; + + const doModelReadFromRAM = function(params, functionSave, errorCallback) { + if ( + OB.DS.masterdataBackgroundModels[me.request.source]['data'].length === 0 + ) { + me.trigger('ready'); + return; + } + let parameters = {}; + parameters._data = + OB.DS.masterdataBackgroundModels[me.request.source]['data']; + parameters._model = + OB.DS.masterdataBackgroundModels[me.request.source]['model']; + const lastUpdated_ = + OB.DS.masterdataBackgroundModels[me.request.source]['lastUpdated']; + const totalRows = + OB.DS.masterdataBackgroundModels[me.request.source]['totalRows']; + parameters._offset = 0; // in background all the pages are concatenated into one + + const success = function() { + OB.info( + '[sdreresh-' + + (incremental ? 'inc' : 'full') + + '] The model ' + + me.request.model.prototype.modelName + + ' has finished saving in db with a total of ' + + parameters._data.length + + ' records. ' + ); + updateModelLastUpdatedTimestamp( + lastUpdated_, + parameters._data, + totalRows + ); + me.trigger('ready'); + }; + functionSave(parameters, success, errorCallback); + }; + + handleIncrementalRequest = function( + limit, + offset, + params, + incremental, + lastId, + background + ) { + params = params || {}; + params._limit = limit; + params._offset = offset; + params._count = OB.UTIL.localStorage.getItem( + 'recordsFromBackendFor' + me.request.model.prototype.modelName + ) + ? parseInt( + OB.UTIL.localStorage.getItem( + 'recordsFromBackendFor' + me.request.model.prototype.modelName + ), + 10 + ) + : 0; + params._isMasterdata = true; + params.overrideDefaultTimeout = true; + params.lastId = lastId; + params.incremental = incremental; + + if (background === undefined) { + // foreground + doModelRequest( + params, + function(params, successCallback, errorCallback) { + doModelDataSave(params, successCallback, errorCallback); + }, + handleError + ); + } else if (background === 'background-request') { + doModelRequest( + params, + function(params, successCallback, errorCallback) { + doModelDataSaveInRAM(params, successCallback, errorCallback); + }, + handleError + ); + } else if (background === 'background-save') { + doModelReadFromRAM( + params, + function(params, successCallback, errorCallback) { + doModelDataSave(params, successCallback, errorCallback); + }, + handleError + ); + } + }; + this.cache = null; var lastId = null; // First request don't have lastId handleIncrementalRequest( @@ -887,7 +1037,8 @@ 0, params, incremental, - lastId + lastId, + background ); }; diff -r fc8eea1df2d4 -r dcdaa8c28650 web/org.openbravo.mobile.core/source/model/ob-terminal-model.js --- a/web/org.openbravo.mobile.core/source/model/ob-terminal-model.js Mon Aug 26 12:05:12 2019 +0200 +++ b/web/org.openbravo.mobile.core/source/model/ob-terminal-model.js Wed Jul 31 17:55:38 2019 +0200 @@ -1985,7 +1985,7 @@ OB.UTIL.showLoading(false); }, - loadModels: function(windows, incremental, callback) { + loadModels: function(windows, incremental, parentCallback, background) { var i, j, windowName, @@ -1997,6 +1997,16 @@ c, path; + const callback = function() { + OB.info( + '[sdrefresh] Finished loading models ' + + (incremental ? 'incrementally' : 'full') + + '.' + + (background ? ' (' + background + ' )' : '') + ); + parentCallback(); + }; + if (OB.MobileApp.model.get("loggedOffline")) { if (callback instanceof Function) { callback(); @@ -2014,7 +2024,8 @@ OB.info( "[sdrefresh] Load models " + (incremental ? "incrementally" : "full") + - "." + '.' + + (background ? ' (' + background + ' )' : '') ); for (i = 0; i < windows.length; i++) { @@ -2056,9 +2067,20 @@ _.extend(datasources, Backbone.Events); - OB.debug("[sdrefresh] window: " + windowName); + OB.debug( + '[sdrefresh] window: ' + + windowName + + (background ? '. (' + background + ' )' : '') + ); - OB.Dal.loadModels(false, datasources, null, incremental, callback); + OB.Dal.loadModels( + false, + datasources, + null, + incremental, + callback, + background + ); this.postLoadModels(); }, 41027-incrementalRefresh-posterminal-18q3-newFormatter.diff [^] (6,531 bytes) 2019-08-27 11:29 [Show Content] [Hide Content] diff -r 542fb729bed2 -r a22a1e7ab7af web/org.openbravo.retail.posterminal/js/utils/ob-utilitiesuipos.js --- a/web/org.openbravo.retail.posterminal/js/utils/ob-utilitiesuipos.js Mon Aug 26 12:05:12 2019 +0200 +++ b/web/org.openbravo.retail.posterminal/js/utils/ob-utilitiesuipos.js Wed Jul 31 17:54:03 2019 +0200 @@ -11,6 +11,9 @@ OB.UTIL = window.OB.UTIL || {}; +OB.UTIL.masterdataRefreshStatus = ''; +OB.UTIL.backgroundMasterdataRefreshEnabled; + OB.UTIL.sendLastTerminalStatusValues = function(callback) { var process = new OB.DS.Process( "org.openbravo.retail.posterminal.process.LastTerminalStatusTimestamps" @@ -673,12 +676,53 @@ }; OB.UTIL.checkRefreshMasterData = function() { + // this code is called on: + // - ticket close + // - timeout of force refresh time + // - window navigation if ( OB.MobileApp.model.get("refreshMasterdata") === true && OB.UTIL.refreshMasterDataGetProperty("allowedIncrementalRefresh") ) { - OB.UTIL.clearFlagAndTimersRefreshMasterData(); - OB.UTIL.refreshMasterData(); + if ( + OB.UTIL.backgroundMasterdataIsEnabled() && + !OB.UTIL.localStorage.getItem('neededForeGroundMasterDataRefresh') + ) { + // background + // this is the save, the request was called in OB.UTIL.loadModelsIncFunc + if (OB.UTIL.masterdataRefreshStatus !== 'background-request-finished') { + OB.info( + "Cannot start masterdata save because the espected status was 'background-request-finished', but it was: " + + OB.UTIL.masterdataRefreshStatus + ); + } else { + OB.UTIL.clearFlagAndTimersRefreshMasterData(); + if (OB.DS.masterdataBackgroundModels.totalLength > 0) { + OB.UTIL.refreshMasterDataInBackgroundSave(); + } else { + OB.info('No updates in the masterdata.'); + } + } + } else { + // foreground + if (OB.UTIL.localStorage.getItem('neededForeGroundMasterDataRefresh')) { + OB.info( + 'Detected that previous masterdata refresh in background has fail because execeeds the limit of data. Trying normal refresh.' + ); + } + if ( + OB.UTIL.masterdataRefreshStatus !== '' && + OB.UTIL.masterdataRefreshStatus !== 'background-request-finished' + ) { + OB.info( + "Cannot start masterdata refresh in foreground because the espected status was '' or 'background-request-finished', but it was: " + + OB.UTIL.masterdataRefreshStatus + ); + } else { + OB.UTIL.clearFlagAndTimersRefreshMasterData(); + OB.UTIL.refreshMasterDataForeground(); + } + } } }; @@ -691,7 +735,56 @@ } }; -OB.UTIL.refreshMasterData = function() { + +OB.UTIL.refreshMasterDataInBackgroundRequest = function() { + if ( + OB.UTIL.masterdataRefreshStatus !== '' && + OB.UTIL.masterdataRefreshStatus !== 'background-request-finished' + ) { + OB.info( + 'Cannot start the masterdata requests because the expected status was "" or "background-request-finished" but it was: ' + + OB.UTIL.masterdataRefreshStatus + ); + return; + } + OB.UTIL.masterdataRefreshStatus = 'background-request-started'; + OB.DS.masterdataBackgroundModels = {}; + OB.MobileApp.model.loadModels( + null, + true, + function() { + OB.UTIL.masterdataRefreshStatus = 'background-request-finished'; + }, + 'background-request' + ); +}; + +OB.UTIL.refreshMasterDataInBackgroundSave = function() { + OB.UTIL.masterdataRefreshStatus = 'background-save-started'; + if (OB.UTIL.RfidController.isRfidConfigured()) { + OB.UTIL.RfidController.disconnectRFIDDevice(); + } + OB.UTIL.startLoadingSteps(); + OB.MobileApp.model.set('isLoggingIn', true); + OB.UTIL.showLoading(true); + OB.MobileApp.model.loadModels( + null, + true, + function() { + OB.UTIL.masterdataRefreshStatus = ''; + OB.DS.masterdataBackgroundModels = {}; + OB.UTIL.showLoading(false); + if (OB.UTIL.RfidController.isRfidConfigured()) { + OB.UTIL.RfidController.connectRFIDDevice(); + } + OB.MobileApp.model.set('isLoggingIn', false); + }, + 'background-save' + ); +}; + +OB.UTIL.refreshMasterDataForeground = function() { + OB.DS.masterdataBackgroundModels = {}; OB.MobileApp.model.set("secondsToRefreshMasterdata", 3); var counterIntervalId = null; counterIntervalId = setInterval(function() { @@ -700,6 +793,7 @@ OB.MobileApp.model.get("secondsToRefreshMasterdata") - 1 ); if (OB.MobileApp.model.get("secondsToRefreshMasterdata") === 0) { + OB.UTIL.masterdataRefreshStatus = 'foreground-started'; OB.MobileApp.model.set("refreshMasterdataShowPopup", false); clearInterval(counterIntervalId); if (OB.UTIL.RfidController.isRfidConfigured()) { @@ -714,6 +808,8 @@ OB.UTIL.RfidController.connectRFIDDevice(); } OB.MobileApp.model.set("isLoggingIn", false); + OB.UTIL.localStorage.removeItem('neededForeGroundMasterDataRefresh'); + OB.UTIL.masterdataRefreshStatus = ''; }); } }, 1000); @@ -796,8 +892,15 @@ OB.info(msg); OB.UTIL.showWarning(msg); } + if ( + OB.UTIL.backgroundMasterdataIsEnabled() && + !OB.UTIL.localStorage.getItem('neededForeGroundMasterDataRefresh') + ) { + OB.UTIL.refreshMasterDataInBackgroundRequest(); + } OB.MobileApp.model.set("refreshMasterdata", true); if (!OB.UTIL.isNullOrUndefined(minShowIncRefresh) && minShowIncRefresh >= 0) { + // Forced refresh by timeout, ticket close also calls to checkRefreshMasterData var noActivityTimeout = OB.MobileApp.model.get( "refreshMasterdataNoActivityTimeout" ); @@ -811,3 +914,27 @@ } } }; + +OB.UTIL.backgroundMasterdataIsEnabled = function() { + if (OB.UTIL.backgroundMasterdataRefreshEnabled === undefined) { + let preferenceValue = OB.MobileApp.model.hasPermission( + 'OBMOBC_BackgroundMasterdataMaxSize', + true + ); + if ( + !preferenceValue || + (preferenceValue && !isNaN(preferenceValue) && preferenceValue >= 1) + ) { + OB.UTIL.backgroundMasterdataRefreshEnabled = true; + } else { + OB.UTIL.backgroundMasterdataRefreshEnabled = false; + if (isNaN(preferenceValue)) { + OB.warn( + 'OBMOBC_BackgroundMasterdataMaxSize has a value not numeric: ' + + preferenceValue + ); + } + } + } + return OB.UTIL.backgroundMasterdataRefreshEnabled; +}; \ No newline at end of file mobCore_OldFormatter_1.diff [^] (9,127 bytes) 2019-08-30 15:12 [Show Content] [Hide Content] # HG changeset patch # User Gorka Gil <gorka.gil@openbravo.com> # Date 1565096957 -7200 # Node ID 74cff7c7a4469593b37761ca694e2977c3a141ae # Parent e761289583dceec55570c8ec9b21a687c6b0fe98 Related to issue 41027: Create modulescript to mantain refresh on login in existing instances diff -r e761289583dc -r 74cff7c7a446 src-util/modulescript/src/org/openbravo/mobile/core/modulescript/MantainMasterdataRefreshBehaviour41027.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src-util/modulescript/src/org/openbravo/mobile/core/modulescript/MantainMasterdataRefreshBehaviour41027.java Tue Aug 06 15:09:17 2019 +0200 @@ -0,0 +1,55 @@ +/* + ************************************************************************************ + * Copyright (C) 2019 Openbravo S.L.U. + * Licensed under the Openbravo Commercial License version 1.0 + * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html + * or in the legal folder of this module distribution. + ************************************************************************************ + */ + +package org.openbravo.mobile.core.modulescript; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.openbravo.database.ConnectionProvider; +import org.openbravo.modulescript.ModuleScript; +import org.openbravo.modulescript.ModuleScriptExecutionLimits; +import org.openbravo.modulescript.OpenbravoVersion; + +/** + * + * Previous to 19Q4 masterdata is refreshed in each login or F5. + * From 19Q4, this preference OBMOBC_NotAutoLoadIncrementalAtLogin comes set by default to 'Y'. + * This module script will mantain the old behaviour for current instalations. + * + */ +public class MantainMasterdataRefreshBehaviour41027 extends ModuleScript { + + private static final Logger log4j = LogManager.getLogger(); + private static final String RETAIL_PACK_MODULE_ID = "03FAB282A7BF47D3B1B242AC67F7845B"; + + @Override + public void execute() { + try { + ConnectionProvider cp = getConnectionProvider(); + final boolean preferenceExists = MantainMasterdataRefreshBehaviour41027Data.preferenceCreated(cp); + if ( ! preferenceExists ) { + MantainMasterdataRefreshBehaviour41027Data.createPreference(cp); + } + } catch (Exception e) { + handleError(e); + } + } + + @Override + protected ModuleScriptExecutionLimits getModuleScriptExecutionLimits() { + return new ModuleScriptExecutionLimits(RETAIL_PACK_MODULE_ID, null, + new OpenbravoVersion(1, 8, 4700)); // execute when updating till 19Q4 + } + + @Override + protected boolean executeOnInstall() { + return false; + } + +} diff -r e761289583dc -r 74cff7c7a446 src-util/modulescript/src/org/openbravo/mobile/core/modulescript/MantainMasterdataRefreshBehaviour41027_Data.xsql --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src-util/modulescript/src/org/openbravo/mobile/core/modulescript/MantainMasterdataRefreshBehaviour41027_Data.xsql Tue Aug 06 15:09:17 2019 +0200 @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- +/* + ************************************************************************************ + * Copyright (C) 2019 Openbravo S.L.U. + * Licensed under the Openbravo Commercial License version 1.0 + * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html + * or in the legal folder of this module distribution. + ************************************************************************************ + */ +--> +<SqlClass name="MantainMasterdataRefreshBehaviour41027Data" package="org.openbravo.mobile.core.modulescript"> + <SqlMethod name="preferenceCreated" type="preparedStatement" return="boolean"> + <Sql> + <![CDATA[ + SELECT count(*) as exist + FROM DUAL + WHERE EXISTS ( + select 1 as num + from ad_preference + where property='OBMOBC_NotAutoLoadIncrementalAtLogin' + and ad_module_id is null + ) + ]]> + </Sql> + </SqlMethod> + <SqlMethod name="createPreference" type="preparedStatement" return="rowcount"> + <Sql> + <![CDATA[ + INSERT INTO ad_preference ( + ad_preference_id, ad_client_id, ad_org_id, isactive, + createdby, created, updatedby, updated, property, value, selected, ispropertylist + ) VALUES ( + get_uuid(), '0', '0', 'Y', '0', NOW(), '0', NOW(),'OBMOBC_NotAutoLoadIncrementalAtLogin', 'N', 'Y', 'Y') + ]]> + </Sql> + </SqlMethod> +</SqlClass> diff -r e761289583dc -r 74cff7c7a446 src-util/modulescript/src/src/org/openbravo/mobile/core/modulescript/MantainMasterdataRefreshBehaviour41027Data.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src-util/modulescript/src/src/org/openbravo/mobile/core/modulescript/MantainMasterdataRefreshBehaviour41027Data.java Tue Aug 06 15:09:17 2019 +0200 @@ -0,0 +1,123 @@ +//Sqlc generated V1.O00-1 +package org.openbravo.mobile.core.modulescript; + +import java.sql.*; + +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; + +import javax.servlet.ServletException; + +import org.openbravo.data.FieldProvider; +import org.openbravo.database.ConnectionProvider; +import org.openbravo.data.UtilSql; +import org.openbravo.database.SessionInfo; + +@SuppressWarnings("serial") +class MantainMasterdataRefreshBehaviour41027Data implements FieldProvider { +static Logger log4j = LogManager.getLogger(); + private String InitRecordNumber="0"; + public String exist; + + public String getInitRecordNumber() { + return InitRecordNumber; + } + + public String getField(String fieldName) { + if (fieldName.equalsIgnoreCase("exist")) + return exist; + else { + log4j.debug("Field does not exist: " + fieldName); + return null; + } + } + + public static boolean preferenceCreated(ConnectionProvider connectionProvider) throws ServletException { + String strSql = ""; + strSql = strSql + + " SELECT count(*) as exist " + + " FROM DUAL " + + " WHERE EXISTS ( " + + " select 1 as num " + + " from ad_preference " + + " where property='OBMOBC_NotAutoLoadIncrementalAtLogin' " + + " and ad_module_id is null" + + " )"; + + ResultSet result; + boolean boolReturn = false; + PreparedStatement st = null; + + try { + st = connectionProvider.getPreparedStatement(strSql); + + result = st.executeQuery(); + if(result.next()) { + boolReturn = !UtilSql.getValue(result, "exist").equals("0"); + } + result.close(); + } catch(SQLException e){ + if (log4j.isDebugEnabled()) { + log4j.error("SQL error in query: " + strSql, e); + } else { + log4j.error("SQL error in query: " + strSql + " :" + e); + } + throw new ServletException("@CODE=" + Integer.toString(e.getErrorCode()) + "@" + e.getMessage()); + } catch(Exception ex){ + if (log4j.isDebugEnabled()) { + log4j.error("Exception in query: " + strSql, ex); + } else { + log4j.error("Exception in query: " + strSql + " :" + ex); + } + throw new ServletException("@CODE=@" + ex.getMessage()); + } finally { + try { + connectionProvider.releasePreparedStatement(st); + } catch(Exception e){ + log4j.error("Error during release*Statement of query: " + strSql, e); + } + } + return(boolReturn); + } + + public static int createPreference(ConnectionProvider connectionProvider) throws ServletException { + String strSql = ""; + strSql = strSql + + " INSERT INTO ad_preference (" + + " ad_preference_id, ad_client_id, ad_org_id, isactive," + + " createdby, created, updatedby, updated, property, value, selected, ispropertylist" + + " ) VALUES (" + + " get_uuid(), '0', '0', 'Y', '0', NOW(), '0', NOW(),'OBMOBC_NotAutoLoadIncrementalAtLogin', 'N', 'Y', 'Y')"; + + int updateCount = 0; + PreparedStatement st = null; + + try { + st = connectionProvider.getPreparedStatement(strSql); + + SessionInfo.saveContextInfoIntoDB(connectionProvider.getConnection()); + updateCount = st.executeUpdate(); + } catch(SQLException e){ + if (log4j.isDebugEnabled()) { + log4j.error("SQL error in query: " + strSql, e); + } else { + log4j.error("SQL error in query: " + strSql + " :" + e); + } + throw new ServletException("@CODE=" + Integer.toString(e.getErrorCode()) + "@" + e.getMessage()); + } catch(Exception ex){ + if (log4j.isDebugEnabled()) { + log4j.error("Exception in query: " + strSql, ex); + } else { + log4j.error("Exception in query: " + strSql + " :" + ex); + } + throw new ServletException("@CODE=@" + ex.getMessage()); + } finally { + try { + connectionProvider.releasePreparedStatement(st); + } catch(Exception e){ + log4j.error("Error during release*Statement of query: " + strSql, e); + } + } + return(updateCount); + } +} mobCore_OldFormatter_2.diff [^] (32,907 bytes) 2019-08-30 15:12 [Show Content] [Hide Content] diff -r f93d312ddd2f src-db/database/sourcedata/AD_MESSAGE.xml --- a/src-db/database/sourcedata/AD_MESSAGE.xml Fri Aug 30 14:39:38 2019 +0200 +++ b/src-db/database/sourcedata/AD_MESSAGE.xml Fri Aug 30 14:45:25 2019 +0200 @@ -2092,6 +2092,18 @@ <!--C4E1B578B13840ADA3BC8092798E743A--> <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N> <!--C4E1B578B13840ADA3BC8092798E743A--></AD_MESSAGE> +<!--C768AEA530B44845ACBDA07AA15CF291--><AD_MESSAGE> +<!--C768AEA530B44845ACBDA07AA15CF291--> <AD_MESSAGE_ID><![CDATA[C768AEA530B44845ACBDA07AA15CF291]]></AD_MESSAGE_ID> +<!--C768AEA530B44845ACBDA07AA15CF291--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> +<!--C768AEA530B44845ACBDA07AA15CF291--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID> +<!--C768AEA530B44845ACBDA07AA15CF291--> <ISACTIVE><![CDATA[Y]]></ISACTIVE> +<!--C768AEA530B44845ACBDA07AA15CF291--> <VALUE><![CDATA[OBMOBC_MasterdataRequestError]]></VALUE> +<!--C768AEA530B44845ACBDA07AA15CF291--> <MSGTEXT><![CDATA[There was an error in the masterdata requests, aborted current refresh]]></MSGTEXT> +<!--C768AEA530B44845ACBDA07AA15CF291--> <MSGTYPE><![CDATA[W]]></MSGTYPE> +<!--C768AEA530B44845ACBDA07AA15CF291--> <AD_MODULE_ID><![CDATA[08943B85ADF64E708797A753E5B6AAEE]]></AD_MODULE_ID> +<!--C768AEA530B44845ACBDA07AA15CF291--> <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N> +<!--C768AEA530B44845ACBDA07AA15CF291--></AD_MESSAGE> + <!--C88B6F2C58B3477BAEA816BF54559E50--><AD_MESSAGE> <!--C88B6F2C58B3477BAEA816BF54559E50--> <AD_MESSAGE_ID><![CDATA[C88B6F2C58B3477BAEA816BF54559E50]]></AD_MESSAGE_ID> <!--C88B6F2C58B3477BAEA816BF54559E50--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> diff -r f93d312ddd2f src-db/database/sourcedata/AD_PREFERENCE.xml --- a/src-db/database/sourcedata/AD_PREFERENCE.xml Fri Aug 30 14:39:38 2019 +0200 +++ b/src-db/database/sourcedata/AD_PREFERENCE.xml Fri Aug 30 14:45:25 2019 +0200 @@ -22,6 +22,17 @@ <!--01EAFAD3A2204971A35D18E8CEBE9F8C--> <AD_MODULE_ID><![CDATA[08943B85ADF64E708797A753E5B6AAEE]]></AD_MODULE_ID> <!--01EAFAD3A2204971A35D18E8CEBE9F8C--></AD_PREFERENCE> +<!--0280B1B0ED464B34924688C1C678A52A--><AD_PREFERENCE> +<!--0280B1B0ED464B34924688C1C678A52A--> <AD_PREFERENCE_ID><![CDATA[0280B1B0ED464B34924688C1C678A52A]]></AD_PREFERENCE_ID> +<!--0280B1B0ED464B34924688C1C678A52A--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> +<!--0280B1B0ED464B34924688C1C678A52A--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID> +<!--0280B1B0ED464B34924688C1C678A52A--> <ISACTIVE><![CDATA[Y]]></ISACTIVE> +<!--0280B1B0ED464B34924688C1C678A52A--> <VALUE><![CDATA[Y]]></VALUE> +<!--0280B1B0ED464B34924688C1C678A52A--> <PROPERTY><![CDATA[OBMOBC_NotAutoLoadIncrementalAtLogin]]></PROPERTY> +<!--0280B1B0ED464B34924688C1C678A52A--> <ISPROPERTYLIST><![CDATA[Y]]></ISPROPERTYLIST> +<!--0280B1B0ED464B34924688C1C678A52A--> <AD_MODULE_ID><![CDATA[08943B85ADF64E708797A753E5B6AAEE]]></AD_MODULE_ID> +<!--0280B1B0ED464B34924688C1C678A52A--></AD_PREFERENCE> + <!--18639B6C06B44324A65D199CD8A32440--><AD_PREFERENCE> <!--18639B6C06B44324A65D199CD8A32440--> <AD_PREFERENCE_ID><![CDATA[18639B6C06B44324A65D199CD8A32440]]></AD_PREFERENCE_ID> <!--18639B6C06B44324A65D199CD8A32440--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> diff -r f93d312ddd2f src-db/database/sourcedata/AD_REF_LIST.xml --- a/src-db/database/sourcedata/AD_REF_LIST.xml Fri Aug 30 14:39:38 2019 +0200 +++ b/src-db/database/sourcedata/AD_REF_LIST.xml Fri Aug 30 14:45:25 2019 +0200 @@ -496,6 +496,18 @@ <!--6D6BEF55A6864548BDF3F2771B669D0C--> <AD_MODULE_ID><![CDATA[08943B85ADF64E708797A753E5B6AAEE]]></AD_MODULE_ID> <!--6D6BEF55A6864548BDF3F2771B669D0C--></AD_REF_LIST> +<!--6E6E9B37800B4F50AAAD606330E887C3--><AD_REF_LIST> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <AD_REF_LIST_ID><![CDATA[6E6E9B37800B4F50AAAD606330E887C3]]></AD_REF_LIST_ID> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <ISACTIVE><![CDATA[Y]]></ISACTIVE> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <VALUE><![CDATA[OBMOBC_BackgroundMasterdataMaxSize]]></VALUE> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <NAME><![CDATA[Background Masterdata Maximum Size]]></NAME> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <DESCRIPTION><![CDATA[Maximum size for all models for incremental masterdata refresh in background. Value -1 disable the background refresh of the masterdata]]></DESCRIPTION> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <AD_REFERENCE_ID><![CDATA[A26BA480E2014707B47257024C3CBFF7]]></AD_REFERENCE_ID> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <AD_MODULE_ID><![CDATA[08943B85ADF64E708797A753E5B6AAEE]]></AD_MODULE_ID> +<!--6E6E9B37800B4F50AAAD606330E887C3--></AD_REF_LIST> + <!--73967117B13C4B5EAEA505E04A7E80A3--><AD_REF_LIST> <!--73967117B13C4B5EAEA505E04A7E80A3--> <AD_REF_LIST_ID><![CDATA[73967117B13C4B5EAEA505E04A7E80A3]]></AD_REF_LIST_ID> <!--73967117B13C4B5EAEA505E04A7E80A3--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> diff -r f93d312ddd2f src-util/modulescript/src/org/openbravo/mobile/core/modulescript/MantainMasterdataRefreshBehaviour41027.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src-util/modulescript/src/org/openbravo/mobile/core/modulescript/MantainMasterdataRefreshBehaviour41027.java Fri Aug 30 14:45:25 2019 +0200 @@ -0,0 +1,55 @@ +/* + ************************************************************************************ + * Copyright (C) 2019 Openbravo S.L.U. + * Licensed under the Openbravo Commercial License version 1.0 + * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html + * or in the legal folder of this module distribution. + ************************************************************************************ + */ + +package org.openbravo.mobile.core.modulescript; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.openbravo.database.ConnectionProvider; +import org.openbravo.modulescript.ModuleScript; +import org.openbravo.modulescript.ModuleScriptExecutionLimits; +import org.openbravo.modulescript.OpenbravoVersion; + +/** + * + * Previous to 19Q4 masterdata is refreshed in each login or F5. + * From 19Q4, this preference OBMOBC_NotAutoLoadIncrementalAtLogin comes set by default to 'Y'. + * This module script will mantain the old behaviour for current instalations. + * + */ +public class MantainMasterdataRefreshBehaviour41027 extends ModuleScript { + + private static final Logger log4j = LogManager.getLogger(); + private static final String RETAIL_PACK_MODULE_ID = "03FAB282A7BF47D3B1B242AC67F7845B"; + + @Override + public void execute() { + try { + ConnectionProvider cp = getConnectionProvider(); + final boolean preferenceExists = MantainMasterdataRefreshBehaviour41027Data.preferenceCreated(cp); + if ( ! preferenceExists ) { + MantainMasterdataRefreshBehaviour41027Data.createPreference(cp); + } + } catch (Exception e) { + handleError(e); + } + } + + @Override + protected ModuleScriptExecutionLimits getModuleScriptExecutionLimits() { + return new ModuleScriptExecutionLimits(RETAIL_PACK_MODULE_ID, null, + new OpenbravoVersion(1, 8, 4700)); // execute when updating till 19Q4 + } + + @Override + protected boolean executeOnInstall() { + return false; + } + +} diff -r f93d312ddd2f src-util/modulescript/src/org/openbravo/mobile/core/modulescript/MantainMasterdataRefreshBehaviour41027_Data.xsql --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src-util/modulescript/src/org/openbravo/mobile/core/modulescript/MantainMasterdataRefreshBehaviour41027_Data.xsql Fri Aug 30 14:45:25 2019 +0200 @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- +/* + ************************************************************************************ + * Copyright (C) 2019 Openbravo S.L.U. + * Licensed under the Openbravo Commercial License version 1.0 + * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html + * or in the legal folder of this module distribution. + ************************************************************************************ + */ +--> +<SqlClass name="MantainMasterdataRefreshBehaviour41027Data" package="org.openbravo.mobile.core.modulescript"> + <SqlMethod name="preferenceCreated" type="preparedStatement" return="boolean"> + <Sql> + <![CDATA[ + SELECT count(*) as exist + FROM DUAL + WHERE EXISTS ( + select 1 as num + from ad_preference + where property='OBMOBC_NotAutoLoadIncrementalAtLogin' + and ad_module_id is null + ) + ]]> + </Sql> + </SqlMethod> + <SqlMethod name="createPreference" type="preparedStatement" return="rowcount"> + <Sql> + <![CDATA[ + INSERT INTO ad_preference ( + ad_preference_id, ad_client_id, ad_org_id, isactive, + createdby, created, updatedby, updated, property, value, selected, ispropertylist + ) VALUES ( + get_uuid(), '0', '0', 'Y', '0', NOW(), '0', NOW(),'OBMOBC_NotAutoLoadIncrementalAtLogin', 'N', 'Y', 'Y') + ]]> + </Sql> + </SqlMethod> +</SqlClass> diff -r f93d312ddd2f src-util/modulescript/src/src/org/openbravo/mobile/core/modulescript/MantainMasterdataRefreshBehaviour41027Data.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src-util/modulescript/src/src/org/openbravo/mobile/core/modulescript/MantainMasterdataRefreshBehaviour41027Data.java Fri Aug 30 14:45:25 2019 +0200 @@ -0,0 +1,123 @@ +//Sqlc generated V1.O00-1 +package org.openbravo.mobile.core.modulescript; + +import java.sql.*; + +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; + +import javax.servlet.ServletException; + +import org.openbravo.data.FieldProvider; +import org.openbravo.database.ConnectionProvider; +import org.openbravo.data.UtilSql; +import org.openbravo.database.SessionInfo; + +@SuppressWarnings("serial") +class MantainMasterdataRefreshBehaviour41027Data implements FieldProvider { +static Logger log4j = LogManager.getLogger(); + private String InitRecordNumber="0"; + public String exist; + + public String getInitRecordNumber() { + return InitRecordNumber; + } + + public String getField(String fieldName) { + if (fieldName.equalsIgnoreCase("exist")) + return exist; + else { + log4j.debug("Field does not exist: " + fieldName); + return null; + } + } + + public static boolean preferenceCreated(ConnectionProvider connectionProvider) throws ServletException { + String strSql = ""; + strSql = strSql + + " SELECT count(*) as exist " + + " FROM DUAL " + + " WHERE EXISTS ( " + + " select 1 as num " + + " from ad_preference " + + " where property='OBMOBC_NotAutoLoadIncrementalAtLogin' " + + " and ad_module_id is null" + + " )"; + + ResultSet result; + boolean boolReturn = false; + PreparedStatement st = null; + + try { + st = connectionProvider.getPreparedStatement(strSql); + + result = st.executeQuery(); + if(result.next()) { + boolReturn = !UtilSql.getValue(result, "exist").equals("0"); + } + result.close(); + } catch(SQLException e){ + if (log4j.isDebugEnabled()) { + log4j.error("SQL error in query: " + strSql, e); + } else { + log4j.error("SQL error in query: " + strSql + " :" + e); + } + throw new ServletException("@CODE=" + Integer.toString(e.getErrorCode()) + "@" + e.getMessage()); + } catch(Exception ex){ + if (log4j.isDebugEnabled()) { + log4j.error("Exception in query: " + strSql, ex); + } else { + log4j.error("Exception in query: " + strSql + " :" + ex); + } + throw new ServletException("@CODE=@" + ex.getMessage()); + } finally { + try { + connectionProvider.releasePreparedStatement(st); + } catch(Exception e){ + log4j.error("Error during release*Statement of query: " + strSql, e); + } + } + return(boolReturn); + } + + public static int createPreference(ConnectionProvider connectionProvider) throws ServletException { + String strSql = ""; + strSql = strSql + + " INSERT INTO ad_preference (" + + " ad_preference_id, ad_client_id, ad_org_id, isactive," + + " createdby, created, updatedby, updated, property, value, selected, ispropertylist" + + " ) VALUES (" + + " get_uuid(), '0', '0', 'Y', '0', NOW(), '0', NOW(),'OBMOBC_NotAutoLoadIncrementalAtLogin', 'N', 'Y', 'Y')"; + + int updateCount = 0; + PreparedStatement st = null; + + try { + st = connectionProvider.getPreparedStatement(strSql); + + SessionInfo.saveContextInfoIntoDB(connectionProvider.getConnection()); + updateCount = st.executeUpdate(); + } catch(SQLException e){ + if (log4j.isDebugEnabled()) { + log4j.error("SQL error in query: " + strSql, e); + } else { + log4j.error("SQL error in query: " + strSql + " :" + e); + } + throw new ServletException("@CODE=" + Integer.toString(e.getErrorCode()) + "@" + e.getMessage()); + } catch(Exception ex){ + if (log4j.isDebugEnabled()) { + log4j.error("Exception in query: " + strSql, ex); + } else { + log4j.error("Exception in query: " + strSql + " :" + ex); + } + throw new ServletException("@CODE=@" + ex.getMessage()); + } finally { + try { + connectionProvider.releasePreparedStatement(st); + } catch(Exception e){ + log4j.error("Error during release*Statement of query: " + strSql, e); + } + } + return(updateCount); + } +} diff -r f93d312ddd2f web/org.openbravo.mobile.core/source/data/ob-dal.js --- a/web/org.openbravo.mobile.core/source/data/ob-dal.js Fri Aug 30 14:39:38 2019 +0200 +++ b/web/org.openbravo.mobile.core/source/data/ob-dal.js Fri Aug 30 14:45:25 2019 +0200 @@ -1539,7 +1539,7 @@ * * */ - OB.Dal.loadModels = function (online, models, data, incremental, callback) { + OB.Dal.loadModels = function (online, models, data, incremental, callback, background) { var timestamp = 0; var key; @@ -1576,6 +1576,7 @@ // We can safely set the POSLastIncRefresh timestamp now. OB.UTIL.localStorage.setItem('POSLastIncRefresh', new Date().getTime()); dalLoadModelsCallback(); + return; } if ( OB.MobileApp.model.get('modelsToLoad').length === 0 && OB.UTIL.queueStatus(models._LoadQueue || {})) { @@ -1728,23 +1729,27 @@ } } }; - OB.Data.localDB.transaction( + if (incremental) { + finishTransaction(); + } else { + OB.Data.localDB.transaction( - function (tx) { - tx.executeSql('select count(1) as totalRecords from ' + item.prototype.tableName, [], function (tx, result) { - logMsgForTransaction( - true, item.prototype.modelName, result.rows.item(0).totalRecords); - checkRecordsWithBackend( - item.prototype.modelName, result.rows.item(0).totalRecords); + function (tx) { + tx.executeSql('select count(1) as totalRecords from ' + item.prototype.tableName, [], function (tx, result) { + logMsgForTransaction( + true, item.prototype.modelName, result.rows.item(0).totalRecords); + checkRecordsWithBackend( + item.prototype.modelName, result.rows.item(0).totalRecords); + }, function () { + logMsgForTransaction(false, item.prototype.modelName); + }); + }, function (errorMsg) { + OB.error(errorMsg); + finishTransaction(); }, function () { - logMsgForTransaction(false, item.prototype.modelName); + finishTransaction(); }); - }, function (errorMsg) { - OB.error(errorMsg); - finishTransaction(); - }, function () { - finishTransaction(); - }); + } } // Skip load of models if it's a incremental refresh and the request timeout has been reached @@ -1760,7 +1765,7 @@ item.params.terminalTime = currentDate; item.params.terminalTimeOffset = currentDate.getTimezoneOffset(); } - ds.load(item.params, incremental); + ds.load(item.params, incremental, background); } } else if ( item && item.prototype.remote && OB.MobileApp.model.hasPermission(item.prototype.remote, true)) { diff -r f93d312ddd2f web/org.openbravo.mobile.core/source/data/ob-datasource.js --- a/web/org.openbravo.mobile.core/source/data/ob-datasource.js Fri Aug 30 14:39:38 2019 +0200 +++ b/web/org.openbravo.mobile.core/source/data/ob-datasource.js Fri Aug 30 14:45:25 2019 +0200 @@ -20,6 +20,8 @@ OB.DS.requestAllowed = isAllowed; }; + OB.DS.masterdataBackgroundModels = {}; // To store the models loaded in the masterdata refresh done in background + function serviceSuccess(inSender, inResponse, callback, tx, requestCallback) { if (inResponse._entityname) { callback([inResponse]); @@ -525,9 +527,8 @@ }; _.extend(OB.DS.DataSource.prototype, Backbone.Events); - OB.DS.DataSource.prototype.load = function (params, incremental) { + OB.DS.DataSource.prototype.load = function (params, incremental, background) { this.modelPagination = 1; - OB.info('[sdreresh-' + (incremental ? 'inc' : 'full') + '] The model ' + this.request.model.prototype.modelName + ' has started masterdata load'); var me = this, handleError, handleIncrementalRequest, dataLoaded = 0; OB.UTIL.localStorage.setItem('recordsFromBackendFor' + me.request.model.prototype.modelName, 0); @@ -537,16 +538,29 @@ me.trigger('ready', 'failed'); }; - handleIncrementalRequest = function ( - limit, offset, params, incremental, lastId) { - params = params || {}; - params._limit = limit; - params._offset = offset; - params._count = OB.UTIL.localStorage.getItem('recordsFromBackendFor' + me.request.model.prototype.modelName) ? parseInt( - OB.UTIL.localStorage.getItem('recordsFromBackendFor' + me.request.model.prototype.modelName), 10) : 0; - params._isMasterdata = true; - params.overrideDefaultTimeout = true; - params.lastId = lastId; + + const updateModelLastUpdatedTimestamp = function ( + lastUpdated, data, totalRows) { + if (lastUpdated && data.length > 0) { + if ( + OB.UTIL.localStorage.getItem('requestTimestamp' + me.request.model.prototype.modelName) && OB.UTIL.localStorage.getItem('requestTimestamp' + me.request.model.prototype.modelName) !== 'null') { + OB.UTIL.localStorage.setItem('lastUpdatedTimestamp' + me.request.model.prototype.modelName, OB.UTIL.localStorage.getItem('requestTimestamp' + me.request.model.prototype.modelName)); + } else { + OB.error('[lastUpdatedTimestamp] ' + 'local storage (lastUpdatedTimestamp' + me.request.model.prototype.modelName + ') attempted to be set as null. Ignored. Current Value: ' + OB.UTIL.localStorage.getItem('lastUpdatedTimestamp' + me.request.model.prototype.modelName)); + } + OB.UTIL.localStorage.removeItem('requestTimestamp' + me.request.model.prototype.modelName); + OB.UTIL.localStorage.setItem('recordsFromBackendFor' + me.request.model.prototype.modelName, totalRows); + } else { + if ( + OB.UTIL.localStorage.getItem('requestTimestamp' + me.request.model.prototype.modelName) && OB.UTIL.localStorage.getItem('requestTimestamp' + me.request.model.prototype.modelName) !== 'null') { + OB.UTIL.localStorage.setItem('lastUpdatedTimestamp' + me.request.model.prototype.modelName, OB.UTIL.localStorage.getItem('requestTimestamp' + me.request.model.prototype.modelName)); + } + } + }; + + const doModelRequest = function (params, functionSave, errorCallback) { + var offset = params._offset; + var limit = params._limit; if (offset === 0) { OB.UTIL.localStorage.setItem('requestTimestamp' + me.request.model.prototype.modelName, new Date().getTime()); OB.UTIL.showLoadingMessage( @@ -557,6 +571,10 @@ OB.I18N.getLabel('OBMOBC_LoadingMessageModelPage', [ me.request.model.prototype.modelName, offset / limit + 1])); } + delete params._data; + delete params._model; + delete params._lastUpdated; + delete params._totalRows; me.request.exec( params, function (data, message, lastUpdated, totalRows) { var newLastId; @@ -574,49 +592,37 @@ OB.UTIL.localStorage.removeItem('lastUpdatedTimestamp' + me.request.model.prototype.modelName); OB.UTIL.localStorage.setItem('recordsFromBackendFor' + me.request.model.prototype.modelName, totalRows); handleIncrementalRequest( - limit, offset + limit, params, incremental, newLastId); + limit, offset + limit, params, incremental, newLastId, background); } else { OB.UTIL.completeLoadingStep(); OB.debug('[sdreresh-' + (incremental ? 'inc' : 'full') + '] The model ' + me.request.model.prototype.modelName + ' has loaded from ' + offset + ' to ' + (offset + limit + 1) + ' with a ' + data.length + ' records in the pagination ' + me.modelPagination); - OB.info('[sdreresh-' + (incremental ? 'inc' : 'full') + '] The model ' + me.request.model.prototype.modelName + ' has finished loading with a total of ' + dataLoaded + ' records. ' + (me.modelPagination === 1 ? 'There was no pagination.' : 'The number of paginations created were ' + me.modelPagination)); - if (lastUpdated && data.length > 0) { - if ( - OB.UTIL.localStorage.getItem('requestTimestamp' + me.request.model.prototype.modelName) && OB.UTIL.localStorage.getItem('requestTimestamp' + me.request.model.prototype.modelName) !== 'null') { - OB.UTIL.localStorage.setItem('lastUpdatedTimestamp' + me.request.model.prototype.modelName, OB.UTIL.localStorage.getItem('requestTimestamp' + me.request.model.prototype.modelName)); - } else { - OB.error('[lastUpdatedTimestamp] ' + 'local storage (lastUpdatedTimestamp' + me.request.model.prototype.modelName + ') attempted to be set as null. Ignored. Current Value: ' + OB.UTIL.localStorage.getItem('lastUpdatedTimestamp' + me.request.model.prototype.modelName)); - } - OB.UTIL.localStorage.removeItem('requestTimestamp' + me.request.model.prototype.modelName); - OB.UTIL.localStorage.setItem('recordsFromBackendFor' + me.request.model.prototype.modelName, totalRows); - } else { - if ( - OB.UTIL.localStorage.getItem('requestTimestamp' + me.request.model.prototype.modelName) && OB.UTIL.localStorage.getItem('requestTimestamp' + me.request.model.prototype.modelName) !== 'null') { - OB.UTIL.localStorage.setItem('lastUpdatedTimestamp' + me.request.model.prototype.modelName, OB.UTIL.localStorage.getItem('requestTimestamp' + me.request.model.prototype.modelName)); - } + if (dataLoaded > 0) { + OB.info('[sdreresh-' + (incremental ? 'inc' : 'full') + '] The model ' + me.request.model.prototype.modelName + ' has finished loading with a total of ' + dataLoaded + ' records. ' + (me.modelPagination === 1 ? 'There was no pagination.' : 'The number of paginations created were ' + me.modelPagination)); } + + if (background === undefined) { + updateModelLastUpdatedTimestamp(lastUpdated, data, totalRows); + } + me.trigger('ready'); } } if (data.exception) { OB.error('Error in datasource: ' + data.exception); + OB.DS.masterdataBackgroundModels = {}; me.trigger('ready', 'failed'); return; } if (me.request.model && me.request.model.prototype.online) { me.cache = me.cache ? me.cache.concat(data) : data; } - if (me.request.model && !me.request.model.prototype.online) { - if (offset === 0) { - OB.Dal.initCache( - me.request.model, data, success, handleError, incremental); - } else { - OB.Dal.insertData( - me.request.model, data, success, handleError, incremental, dataLoaded); - } - } else { - success(); - } + + params._data = data; + params._model = me.request.model; + params._lastUpdated = lastUpdated; + params._totalRows = totalRows; + functionSave(params, success, errorCallback); }, function (data) { OB.UTIL.Debug.execute(function () { if (data && data.exception && data.exception.message) { @@ -624,6 +630,10 @@ return; } }); + OB.DS.masterdataBackgroundModels = {}; + + OB.info(OB.I18N.getLabel('OBMOBC_MasterdataRequestError')); + OB.UTIL.showI18NWarning('OBMOBC_MasterdataRequestError'); if ( data && data.exception && data.exception.message && data.exception.message === 'Application server is not available.') { me.trigger('ready', 'timeout'); @@ -635,11 +645,112 @@ me.request.source).getServiceTimeout(5000) * 20); }; + const doModelDataSave = function (params, success, handleError) { + const offset = params._offset; + const data = params._data; + const model = params._model; + if (model && !model.prototype.online) { + if (offset === 0) { + OB.Dal.initCache(model, data, success, handleError, incremental); + } else { + OB.Dal.insertData( + model, data, success, handleError, incremental, dataLoaded); + } + } else { + success(); + } + }; + + const doModelDataSaveInRAM = function (params, success, handleError) { + const data = params._data; + const limit = params._limit; + const currentLength = data.length; + const backgroundLimit = OB.MobileApp.model.hasPermission('OBMOBC_BackgroundMasterdataMaxSize', true) ? OB.MobileApp.model.hasPermission('OBMOBC_BackgroundMasterdataMaxSize', true) : limit; + if ( + OB.DS.masterdataBackgroundModels['totalLength'] + currentLength > backgroundLimit) { + OB.info('Failed to do masterdata refresh in background because exceeds the limit of data. Trying normal refresh.'); + OB.UTIL.localStorage.setItem('neededForeGroundMasterDataRefresh'); + OB.UTIL.refreshMasterDataForeground(); + OB.DS.masterdataBackgroundModels = {}; + return; + } + if (!OB.DS.masterdataBackgroundModels.hasOwnProperty(me.request.source)) { + OB.DS.masterdataBackgroundModels[me.request.source] = {}; + OB.DS.masterdataBackgroundModels[me.request.source]['data'] = []; + } + + OB.DS.masterdataBackgroundModels[me.request.source]['data'] = [...OB.DS.masterdataBackgroundModels[me.request.source]['data'], ...params._data]; + + OB.DS.masterdataBackgroundModels[me.request.source]['model'] = params._model; + OB.DS.masterdataBackgroundModels[me.request.source]['lastUpdated'] = params._lastUpdated; + OB.DS.masterdataBackgroundModels[me.request.source]['totalRows'] = params._totalRows; + + OB.DS.masterdataBackgroundModels[me.request.source]['lastUpdated'] = me.request.lastUpdated; + + if (!OB.DS.masterdataBackgroundModels.hasOwnProperty('totalLength')) { + OB.DS.masterdataBackgroundModels['totalLength'] = 0; + } + OB.DS.masterdataBackgroundModels['totalLength'] += currentLength; + success(); + }; + + const doModelReadFromRAM = function (params, functionSave, errorCallback) { + if ( + OB.DS.masterdataBackgroundModels[me.request.source]['data'].length === 0) { + me.trigger('ready'); + return; + } + let parameters = {}; + parameters._data = OB.DS.masterdataBackgroundModels[me.request.source]['data']; + parameters._model = OB.DS.masterdataBackgroundModels[me.request.source]['model']; + const lastUpdated_ = OB.DS.masterdataBackgroundModels[me.request.source]['lastUpdated']; + const totalRows = OB.DS.masterdataBackgroundModels[me.request.source]['totalRows']; + parameters._offset = 0; // in background all the pages are concatenated into one + const success = function () { + OB.info('[sdreresh-' + (incremental ? 'inc' : 'full') + '] The model ' + me.request.model.prototype.modelName + ' has finished saving in db with a total of ' + parameters._data.length + ' records. '); + updateModelLastUpdatedTimestamp( + lastUpdated_, parameters._data, totalRows); + me.trigger('ready'); + }; + functionSave(parameters, success, errorCallback); + }; + + handleIncrementalRequest = function ( + limit, offset, params, incremental, lastId, background) { + params = params || {}; + params._limit = limit; + params._offset = offset; + params._count = OB.UTIL.localStorage.getItem('recordsFromBackendFor' + me.request.model.prototype.modelName) ? parseInt( + OB.UTIL.localStorage.getItem('recordsFromBackendFor' + me.request.model.prototype.modelName), 10) : 0; + params._isMasterdata = true; + params.overrideDefaultTimeout = true; + params.lastId = lastId; + params.incremental = incremental; + + if (background === undefined) { + // foreground + doModelRequest( + params, function (params, successCallback, errorCallback) { + doModelDataSave(params, successCallback, errorCallback); + }, handleError); + } else if (background === 'background-request') { + doModelRequest( + params, function (params, successCallback, errorCallback) { + doModelDataSaveInRAM(params, successCallback, errorCallback); + }, handleError); + } else if (background === 'background-save') { + doModelReadFromRAM( + params, function (params, successCallback, errorCallback) { + doModelDataSave(params, successCallback, errorCallback); + }, handleError); + } + }; + this.cache = null; var lastId = null; // First request don't have lastId handleIncrementalRequest( OB.MobileApp.model.hasPermission('OBMOBC_MasterdataBatchSize', true) ? OB.DEC.abs( - OB.MobileApp.model.hasPermission('OBMOBC_MasterdataBatchSize', true)) : 10000, 0, params, incremental, lastId); + OB.MobileApp.model.hasPermission('OBMOBC_MasterdataBatchSize', true)) : 10000, 0, params, incremental, lastId, background); }; OB.DS.DataSource.prototype.find = function (filter, callback) { diff -r f93d312ddd2f web/org.openbravo.mobile.core/source/model/ob-terminal-model.js --- a/web/org.openbravo.mobile.core/source/model/ob-terminal-model.js Fri Aug 30 14:39:38 2019 +0200 +++ b/web/org.openbravo.mobile.core/source/model/ob-terminal-model.js Fri Aug 30 14:45:25 2019 +0200 @@ -1817,10 +1817,15 @@ } }, - loadModels: function (windows, incremental, callback) { + loadModels: function (windows, incremental, parentCallback, background) { var i, j, windowName, windowClass, windowDatasources, datasources = [], w, c, path; + const callback = function () { + OB.info('[sdrefresh] Finished loading models ' + (incremental ? 'incrementally' : 'full') + '.' + (background ? ' (' + background + ' )' : '')); + parentCallback(); + }; + if (OB.MobileApp.model.get('loggedOffline')) { if (callback instanceof Function) { callback(); @@ -1835,7 +1840,7 @@ }); } - OB.info('[sdrefresh] Load models ' + (incremental ? 'incrementally' : 'full') + '.'); + OB.info('[sdrefresh] Load models ' + (incremental ? 'incrementally' : 'full') + '.' + (background ? ' (' + background + ' )' : '')); for (i = 0; i < windows.length; i++) { windowClass = windows[i].windowClass; @@ -1868,9 +1873,10 @@ _.extend(datasources, Backbone.Events); - OB.debug('[sdrefresh] window: ' + windowName); + OB.debug('[sdrefresh] window: ' + windowName + (background ? '. (' + background + ' )' : '')); - OB.Dal.loadModels(false, datasources, null, incremental, callback); + OB.Dal.loadModels( + false, datasources, null, incremental, callback, background); this.postLoadModels(); }, mobCore_OldFormatter_3.diff [^] (759 bytes) 2019-08-30 15:12 [Show Content] [Hide Content] diff -r a11153f696db web/org.openbravo.mobile.core/source/data/ob-datasource.js --- a/web/org.openbravo.mobile.core/source/data/ob-datasource.js Fri Aug 30 15:02:49 2019 +0200 +++ b/web/org.openbravo.mobile.core/source/data/ob-datasource.js Fri Aug 30 15:03:44 2019 +0200 @@ -632,7 +632,8 @@ }); OB.DS.masterdataBackgroundModels = {}; - OB.info(OB.I18N.getLabel('OBMOBC_MasterdataRequestError')); + OB.info( + OB.I18N.getLabel('OBMOBC_MasterdataRequestError') + '. URL which failed: ' + me.request.source); OB.UTIL.showI18NWarning('OBMOBC_MasterdataRequestError'); if ( data && data.exception && data.exception.message && data.exception.message === 'Application server is not available.') { posterminal_OldFormatter.diff [^] (6,524 bytes) 2019-08-30 15:13 [Show Content] [Hide Content] diff -r 3e498aa25675 web/org.openbravo.retail.posterminal/js/utils/ob-utilitiesuipos.js --- a/web/org.openbravo.retail.posterminal/js/utils/ob-utilitiesuipos.js Fri Aug 30 14:58:19 2019 +0200 +++ b/web/org.openbravo.retail.posterminal/js/utils/ob-utilitiesuipos.js Fri Aug 30 14:59:03 2019 +0200 @@ -11,6 +11,9 @@ OB.UTIL = window.OB.UTIL || {}; +OB.UTIL.masterdataRefreshStatus = ''; +OB.UTIL.backgroundMasterdataRefreshEnabled; + OB.UTIL.sendLastTerminalStatusValues = function (callback) { var process = new OB.DS.Process('org.openbravo.retail.posterminal.process.LastTerminalStatusTimestamps'); process.exec({ @@ -559,10 +562,39 @@ }; OB.UTIL.checkRefreshMasterData = function () { + // this code is called on: + // - ticket close + // - timeout of force refresh time + // - window navigation if ( OB.MobileApp.model.get('refreshMasterdata') === true && OB.UTIL.refreshMasterDataGetProperty('allowedIncrementalRefresh')) { - OB.UTIL.clearFlagAndTimersRefreshMasterData(); - OB.UTIL.refreshMasterData(); + if ( + OB.UTIL.backgroundMasterdataIsEnabled() && !OB.UTIL.localStorage.getItem('neededForeGroundMasterDataRefresh')) { + // background + // this is the save, the request was called in OB.UTIL.loadModelsIncFunc + if (OB.UTIL.masterdataRefreshStatus !== 'background-request-finished') { + OB.info("Cannot start masterdata save because the espected status was 'background-request-finished', but it was: " + OB.UTIL.masterdataRefreshStatus); + } else { + OB.UTIL.clearFlagAndTimersRefreshMasterData(); + if (OB.DS.masterdataBackgroundModels.totalLength > 0) { + OB.UTIL.refreshMasterDataInBackgroundSave(); + } else { + OB.info('No updates in the masterdata.'); + } + } + } else { + // foreground + if (OB.UTIL.localStorage.getItem('neededForeGroundMasterDataRefresh')) { + OB.info('Detected that previous masterdata refresh in background has fail because execeeds the limit of data. Trying normal refresh.'); + } + if ( + OB.UTIL.masterdataRefreshStatus !== '' && OB.UTIL.masterdataRefreshStatus !== 'background-request-finished') { + OB.info("Cannot start masterdata refresh in foreground because the espected status was '' or 'background-request-finished', but it was: " + OB.UTIL.masterdataRefreshStatus); + } else { + OB.UTIL.clearFlagAndTimersRefreshMasterData(); + OB.UTIL.refreshMasterDataForeground(); + } + } } }; @@ -572,12 +604,49 @@ OB.UTIL.checkRefreshMasterData(); } }; -OB.UTIL.refreshMasterData = function () { + +OB.UTIL.refreshMasterDataInBackgroundRequest = function () { + if ( + OB.UTIL.masterdataRefreshStatus !== '' && OB.UTIL.masterdataRefreshStatus !== 'background-request-finished') { + OB.info('Cannot start the masterdata requests because the expected status was "" or "background-request-finished" but it was: ' + OB.UTIL.masterdataRefreshStatus); + return; + } + OB.UTIL.masterdataRefreshStatus = 'background-request-started'; + OB.DS.masterdataBackgroundModels = {}; + OB.MobileApp.model.loadModels( + null, true, function () { + OB.UTIL.masterdataRefreshStatus = 'background-request-finished'; + }, 'background-request'); +}; + +OB.UTIL.refreshMasterDataInBackgroundSave = function () { + OB.UTIL.masterdataRefreshStatus = 'background-save-started'; + if (OB.UTIL.RfidController.isRfidConfigured()) { + OB.UTIL.RfidController.disconnectRFIDDevice(); + } + OB.UTIL.startLoadingSteps(); + OB.MobileApp.model.set('isLoggingIn', true); + OB.UTIL.showLoading(true); + OB.MobileApp.model.loadModels( + null, true, function () { + OB.UTIL.masterdataRefreshStatus = ''; + OB.DS.masterdataBackgroundModels = {}; + OB.UTIL.showLoading(false); + if (OB.UTIL.RfidController.isRfidConfigured()) { + OB.UTIL.RfidController.connectRFIDDevice(); + } + OB.MobileApp.model.set('isLoggingIn', false); + }, 'background-save'); +}; + +OB.UTIL.refreshMasterDataForeground = function () { + OB.DS.masterdataBackgroundModels = {}; OB.MobileApp.model.set('secondsToRefreshMasterdata', 3); var counterIntervalId = null; counterIntervalId = setInterval(function () { OB.MobileApp.model.set('secondsToRefreshMasterdata', OB.MobileApp.model.get('secondsToRefreshMasterdata') - 1); if (OB.MobileApp.model.get('secondsToRefreshMasterdata') === 0) { + OB.UTIL.masterdataRefreshStatus = 'foreground-started'; OB.MobileApp.model.set('refreshMasterdataShowPopup', false); clearInterval(counterIntervalId); if (OB.UTIL.RfidController.isRfidConfigured()) { @@ -592,6 +661,8 @@ OB.UTIL.RfidController.connectRFIDDevice(); } OB.MobileApp.model.set('isLoggingIn', false); + OB.UTIL.localStorage.removeItem('neededForeGroundMasterDataRefresh'); + OB.UTIL.masterdataRefreshStatus = ''; }); } }, 1000); @@ -656,8 +727,13 @@ OB.info(msg); OB.UTIL.showWarning(msg); } + if ( + OB.UTIL.backgroundMasterdataIsEnabled() && !OB.UTIL.localStorage.getItem('neededForeGroundMasterDataRefresh')) { + OB.UTIL.refreshMasterDataInBackgroundRequest(); + } OB.MobileApp.model.set('refreshMasterdata', true); if (!OB.UTIL.isNullOrUndefined(minShowIncRefresh) && minShowIncRefresh >= 0) { + // Forced refresh by timeout, ticket close also calls to checkRefreshMasterData var noActivityTimeout = OB.MobileApp.model.get('refreshMasterdataNoActivityTimeout'); if (OB.UTIL.isNullOrUndefined(noActivityTimeout)) { OB.MobileApp.model.set('refreshMasterdataNoActivityTimeout', true); @@ -670,6 +746,21 @@ } }; +OB.UTIL.backgroundMasterdataIsEnabled = function () { + if (OB.UTIL.backgroundMasterdataRefreshEnabled === undefined) { + let preferenceValue = OB.MobileApp.model.hasPermission('OBMOBC_BackgroundMasterdataMaxSize', true); + if (!preferenceValue || (preferenceValue && !isNaN(preferenceValue) && preferenceValue >= 1)) { + OB.UTIL.backgroundMasterdataRefreshEnabled = true; + } else { + OB.UTIL.backgroundMasterdataRefreshEnabled = false; + if (isNaN(preferenceValue)) { + OB.warn('OBMOBC_BackgroundMasterdataMaxSize has a value not numeric: ' + preferenceValue); + } + } + } + return OB.UTIL.backgroundMasterdataRefreshEnabled; +}; + OB.UTIL.getCalculatedPriceForService = function ( line, product, relatedLines, serviceLineQty, callback, errorCallback) { var amountBeforeDiscounts = 0, 41027-incrementalRefresh-mobilecore-18q3-newFormatter-simpleQuotes.diff [^] (26,630 bytes) 2019-09-06 11:49 [Show Content] [Hide Content] diff -r 0998deaab73b src-db/database/sourcedata/AD_MESSAGE.xml --- a/src-db/database/sourcedata/AD_MESSAGE.xml Thu Sep 05 07:49:00 2019 +0200 +++ b/src-db/database/sourcedata/AD_MESSAGE.xml Fri Sep 06 11:40:56 2019 +0200 @@ -1936,6 +1936,18 @@ <!--C4E1B578B13840ADA3BC8092798E743A--> <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N> <!--C4E1B578B13840ADA3BC8092798E743A--></AD_MESSAGE> +<!--C768AEA530B44845ACBDA07AA15CF291--><AD_MESSAGE> +<!--C768AEA530B44845ACBDA07AA15CF291--> <AD_MESSAGE_ID><![CDATA[C768AEA530B44845ACBDA07AA15CF291]]></AD_MESSAGE_ID> +<!--C768AEA530B44845ACBDA07AA15CF291--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> +<!--C768AEA530B44845ACBDA07AA15CF291--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID> +<!--C768AEA530B44845ACBDA07AA15CF291--> <ISACTIVE><![CDATA[Y]]></ISACTIVE> +<!--C768AEA530B44845ACBDA07AA15CF291--> <VALUE><![CDATA[OBMOBC_MasterdataRequestError]]></VALUE> +<!--C768AEA530B44845ACBDA07AA15CF291--> <MSGTEXT><![CDATA[There was an error in the masterdata requests, aborted current refresh]]></MSGTEXT> +<!--C768AEA530B44845ACBDA07AA15CF291--> <MSGTYPE><![CDATA[W]]></MSGTYPE> +<!--C768AEA530B44845ACBDA07AA15CF291--> <AD_MODULE_ID><![CDATA[08943B85ADF64E708797A753E5B6AAEE]]></AD_MODULE_ID> +<!--C768AEA530B44845ACBDA07AA15CF291--> <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N> +<!--C768AEA530B44845ACBDA07AA15CF291--></AD_MESSAGE> + <!--C88B6F2C58B3477BAEA816BF54559E50--><AD_MESSAGE> <!--C88B6F2C58B3477BAEA816BF54559E50--> <AD_MESSAGE_ID><![CDATA[C88B6F2C58B3477BAEA816BF54559E50]]></AD_MESSAGE_ID> <!--C88B6F2C58B3477BAEA816BF54559E50--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> diff -r 0998deaab73b src-db/database/sourcedata/AD_PREFERENCE.xml --- a/src-db/database/sourcedata/AD_PREFERENCE.xml Thu Sep 05 07:49:00 2019 +0200 +++ b/src-db/database/sourcedata/AD_PREFERENCE.xml Fri Sep 06 11:40:56 2019 +0200 @@ -22,6 +22,17 @@ <!--01EAFAD3A2204971A35D18E8CEBE9F8C--> <AD_MODULE_ID><![CDATA[08943B85ADF64E708797A753E5B6AAEE]]></AD_MODULE_ID> <!--01EAFAD3A2204971A35D18E8CEBE9F8C--></AD_PREFERENCE> +<!--0280B1B0ED464B34924688C1C678A52A--><AD_PREFERENCE> +<!--0280B1B0ED464B34924688C1C678A52A--> <AD_PREFERENCE_ID><![CDATA[0280B1B0ED464B34924688C1C678A52A]]></AD_PREFERENCE_ID> +<!--0280B1B0ED464B34924688C1C678A52A--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> +<!--0280B1B0ED464B34924688C1C678A52A--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID> +<!--0280B1B0ED464B34924688C1C678A52A--> <ISACTIVE><![CDATA[Y]]></ISACTIVE> +<!--0280B1B0ED464B34924688C1C678A52A--> <VALUE><![CDATA[Y]]></VALUE> +<!--0280B1B0ED464B34924688C1C678A52A--> <PROPERTY><![CDATA[OBMOBC_NotAutoLoadIncrementalAtLogin]]></PROPERTY> +<!--0280B1B0ED464B34924688C1C678A52A--> <ISPROPERTYLIST><![CDATA[Y]]></ISPROPERTYLIST> +<!--0280B1B0ED464B34924688C1C678A52A--> <AD_MODULE_ID><![CDATA[08943B85ADF64E708797A753E5B6AAEE]]></AD_MODULE_ID> +<!--0280B1B0ED464B34924688C1C678A52A--></AD_PREFERENCE> + <!--18639B6C06B44324A65D199CD8A32440--><AD_PREFERENCE> <!--18639B6C06B44324A65D199CD8A32440--> <AD_PREFERENCE_ID><![CDATA[18639B6C06B44324A65D199CD8A32440]]></AD_PREFERENCE_ID> <!--18639B6C06B44324A65D199CD8A32440--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> diff -r 0998deaab73b src-db/database/sourcedata/AD_REF_LIST.xml --- a/src-db/database/sourcedata/AD_REF_LIST.xml Thu Sep 05 07:49:00 2019 +0200 +++ b/src-db/database/sourcedata/AD_REF_LIST.xml Fri Sep 06 11:40:56 2019 +0200 @@ -366,6 +366,18 @@ <!--685D743ABF804EFBB48B9E7D4C253E02--> <SEQNO><![CDATA[40]]></SEQNO> <!--685D743ABF804EFBB48B9E7D4C253E02--></AD_REF_LIST> +<!--6E6E9B37800B4F50AAAD606330E887C3--><AD_REF_LIST> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <AD_REF_LIST_ID><![CDATA[6E6E9B37800B4F50AAAD606330E887C3]]></AD_REF_LIST_ID> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <ISACTIVE><![CDATA[Y]]></ISACTIVE> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <VALUE><![CDATA[OBMOBC_BackgroundMasterdataMaxSize]]></VALUE> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <NAME><![CDATA[Background Masterdata Maximum Size]]></NAME> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <DESCRIPTION><![CDATA[Maximum size for all models for incremental masterdata refresh in background. Value -1 disable the background refresh of the masterdata]]></DESCRIPTION> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <AD_REFERENCE_ID><![CDATA[A26BA480E2014707B47257024C3CBFF7]]></AD_REFERENCE_ID> +<!--6E6E9B37800B4F50AAAD606330E887C3--> <AD_MODULE_ID><![CDATA[08943B85ADF64E708797A753E5B6AAEE]]></AD_MODULE_ID> +<!--6E6E9B37800B4F50AAAD606330E887C3--></AD_REF_LIST> + <!--73967117B13C4B5EAEA505E04A7E80A3--><AD_REF_LIST> <!--73967117B13C4B5EAEA505E04A7E80A3--> <AD_REF_LIST_ID><![CDATA[73967117B13C4B5EAEA505E04A7E80A3]]></AD_REF_LIST_ID> <!--73967117B13C4B5EAEA505E04A7E80A3--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> diff -r 0998deaab73b web/org.openbravo.mobile.core/source/data/ob-dal.js --- a/web/org.openbravo.mobile.core/source/data/ob-dal.js Thu Sep 05 07:49:00 2019 +0200 +++ b/web/org.openbravo.mobile.core/source/data/ob-dal.js Fri Sep 06 11:40:56 2019 +0200 @@ -2196,7 +2196,14 @@ * * */ - OB.Dal.loadModels = function(online, models, data, incremental, callback) { + OB.Dal.loadModels = function( + online, + models, + data, + incremental, + callback, + background + ) { var timestamp = 0; var key; @@ -2241,6 +2248,7 @@ // We can safely set the POSLastIncRefresh timestamp now. OB.UTIL.localStorage.setItem('POSLastIncRefresh', new Date().getTime()); dalLoadModelsCallback(); + return; } if ( OB.MobileApp.model.get('modelsToLoad').length === 0 && @@ -2468,36 +2476,40 @@ } } }; - OB.Data.localDB.transaction( - function(tx) { - tx.executeSql( - 'select count(1) as totalRecords from ' + - item.prototype.tableName, - [], - function(tx, result) { - logMsgForTransaction( - true, - item.prototype.modelName, - result.rows.item(0).totalRecords - ); - checkRecordsWithBackend( - item.prototype.modelName, - result.rows.item(0).totalRecords - ); - }, - function() { - logMsgForTransaction(false, item.prototype.modelName); - } - ); - }, - function(errorMsg) { - OB.error(errorMsg); - finishTransaction(); - }, - function() { - finishTransaction(); - } - ); + if (incremental) { + finishTransaction(); + } else { + OB.Data.localDB.transaction( + function(tx) { + tx.executeSql( + 'select count(1) as totalRecords from ' + + item.prototype.tableName, + [], + function(tx, result) { + logMsgForTransaction( + true, + item.prototype.modelName, + result.rows.item(0).totalRecords + ); + checkRecordsWithBackend( + item.prototype.modelName, + result.rows.item(0).totalRecords + ); + }, + function() { + logMsgForTransaction(false, item.prototype.modelName); + } + ); + }, + function(errorMsg) { + OB.error(errorMsg); + finishTransaction(); + }, + function() { + finishTransaction(); + } + ); + } } // Skip load of models if it's a incremental refresh and the request timeout has been reached @@ -2513,7 +2525,7 @@ item.params.terminalTime = currentDate; item.params.terminalTimeOffset = currentDate.getTimezoneOffset(); } - ds.load(item.params, incremental); + ds.load(item.params, incremental, background); } } else if ( item && diff -r 0998deaab73b web/org.openbravo.mobile.core/source/data/ob-datasource.js --- a/web/org.openbravo.mobile.core/source/data/ob-datasource.js Thu Sep 05 07:49:00 2019 +0200 +++ b/web/org.openbravo.mobile.core/source/data/ob-datasource.js Fri Sep 06 11:40:56 2019 +0200 @@ -20,6 +20,8 @@ OB.DS.requestAllowed = isAllowed; }; + OB.DS.masterdataBackgroundModels = {}; // To store the models loaded in the masterdata refresh done in background + function serviceSuccess(inSender, inResponse, callback, tx, requestCallback) { if (inResponse._entityname) { callback([inResponse]); @@ -617,15 +619,8 @@ }; _.extend(OB.DS.DataSource.prototype, Backbone.Events); - OB.DS.DataSource.prototype.load = function(params, incremental) { + OB.DS.DataSource.prototype.load = function(params, incremental, background) { this.modelPagination = 1; - OB.info( - '[sdreresh-' + - (incremental ? 'inc' : 'full') + - '] The model ' + - this.request.model.prototype.modelName + - ' has started masterdata load' - ); var me = this, handleError, handleIncrementalRequest, @@ -645,29 +640,67 @@ me.trigger('ready', 'failed'); }; - handleIncrementalRequest = function( - limit, - offset, - params, - incremental, - lastId + + const updateModelLastUpdatedTimestamp = function( + lastUpdated, + data, + totalRows ) { - params = params || {}; - params._limit = limit; - params._offset = offset; - params._count = OB.UTIL.localStorage.getItem( - 'recordsFromBackendFor' + me.request.model.prototype.modelName - ) - ? parseInt( + if (lastUpdated && data.length > 0) { + if ( + OB.UTIL.localStorage.getItem( + 'requestTimestamp' + me.request.model.prototype.modelName + ) && + OB.UTIL.localStorage.getItem( + 'requestTimestamp' + me.request.model.prototype.modelName + ) !== 'null' + ) { + OB.UTIL.localStorage.setItem( + 'lastUpdatedTimestamp' + me.request.model.prototype.modelName, OB.UTIL.localStorage.getItem( - 'recordsFromBackendFor' + me.request.model.prototype.modelName - ), - 10 - ) - : 0; - params._isMasterdata = true; - params.overrideDefaultTimeout = true; - params.lastId = lastId; + 'requestTimestamp' + me.request.model.prototype.modelName + ) + ); + } else { + OB.error( + '[lastUpdatedTimestamp] ' + + 'local storage (lastUpdatedTimestamp' + + me.request.model.prototype.modelName + + ') attempted to be set as null. Ignored. Current Value: ' + + OB.UTIL.localStorage.getItem( + 'lastUpdatedTimestamp' + me.request.model.prototype.modelName + ) + ); + } + OB.UTIL.localStorage.removeItem( + 'requestTimestamp' + me.request.model.prototype.modelName + ); + OB.UTIL.localStorage.setItem( + 'recordsFromBackendFor' + me.request.model.prototype.modelName, + totalRows + ); + } else { + if ( + OB.UTIL.localStorage.getItem( + 'requestTimestamp' + me.request.model.prototype.modelName + ) && + OB.UTIL.localStorage.getItem( + 'requestTimestamp' + me.request.model.prototype.modelName + ) !== 'null' + ) { + OB.UTIL.localStorage.setItem( + 'lastUpdatedTimestamp' + me.request.model.prototype.modelName, + OB.UTIL.localStorage.getItem( + 'requestTimestamp' + me.request.model.prototype.modelName + ) + ); + } + } + }; + + const doModelRequest = function(params, functionSave, errorCallback) { + var offset = params._offset; + var limit = params._limit; if (offset === 0) { OB.UTIL.localStorage.setItem( 'requestTimestamp' + me.request.model.prototype.modelName, @@ -686,6 +719,10 @@ ]) ); } + delete params._data; + delete params._model; + delete params._lastUpdated; + delete params._totalRows; me.request.exec( params, function(data, message, lastUpdated, totalRows) { @@ -727,7 +764,8 @@ offset + limit, params, incremental, - newLastId + newLastId, + background ); } else { OB.UTIL.completeLoadingStep(); @@ -745,106 +783,44 @@ ' records in the pagination ' + me.modelPagination ); - OB.info( - '[sdreresh-' + - (incremental ? 'inc' : 'full') + - '] The model ' + - me.request.model.prototype.modelName + - ' has finished loading with a total of ' + - dataLoaded + - ' records. ' + - (me.modelPagination === 1 - ? 'There was no pagination.' - : 'The number of paginations created were ' + - me.modelPagination) - ); - if (lastUpdated && data.length > 0) { - if ( - OB.UTIL.localStorage.getItem( - 'requestTimestamp' + me.request.model.prototype.modelName - ) && - OB.UTIL.localStorage.getItem( - 'requestTimestamp' + me.request.model.prototype.modelName - ) !== 'null' - ) { - OB.UTIL.localStorage.setItem( - 'lastUpdatedTimestamp' + - me.request.model.prototype.modelName, - OB.UTIL.localStorage.getItem( - 'requestTimestamp' + me.request.model.prototype.modelName - ) - ); - } else { - OB.error( - '[lastUpdatedTimestamp] ' + - 'local storage (lastUpdatedTimestamp' + - me.request.model.prototype.modelName + - ') attempted to be set as null. Ignored. Current Value: ' + - OB.UTIL.localStorage.getItem( - 'lastUpdatedTimestamp' + - me.request.model.prototype.modelName - ) - ); - } - OB.UTIL.localStorage.removeItem( - 'requestTimestamp' + me.request.model.prototype.modelName + if (dataLoaded > 0) { + OB.info( + '[sdreresh-' + + (incremental ? 'inc' : 'full') + + '] The model ' + + me.request.model.prototype.modelName + + ' has finished loading with a total of ' + + dataLoaded + + ' records. ' + + (me.modelPagination === 1 + ? 'There was no pagination.' + : 'The number of paginations created were ' + + me.modelPagination) ); - OB.UTIL.localStorage.setItem( - 'recordsFromBackendFor' + - me.request.model.prototype.modelName, - totalRows - ); - } else { - if ( - OB.UTIL.localStorage.getItem( - 'requestTimestamp' + me.request.model.prototype.modelName - ) && - OB.UTIL.localStorage.getItem( - 'requestTimestamp' + me.request.model.prototype.modelName - ) !== 'null' - ) { - OB.UTIL.localStorage.setItem( - 'lastUpdatedTimestamp' + - me.request.model.prototype.modelName, - OB.UTIL.localStorage.getItem( - 'requestTimestamp' + me.request.model.prototype.modelName - ) - ); - } } + + if (background === undefined) { + updateModelLastUpdatedTimestamp(lastUpdated, data, totalRows); + } + me.trigger('ready'); } } if (data.exception) { OB.error('Error in datasource: ' + data.exception); + OB.DS.masterdataBackgroundModels = {}; me.trigger('ready', 'failed'); return; } if (me.request.model && me.request.model.prototype.online) { me.cache = me.cache ? me.cache.concat(data) : data; } - if (me.request.model && !me.request.model.prototype.online) { - if (offset === 0) { - OB.Dal.initCache( - me.request.model, - data, - success, - handleError, - incremental - ); - } else { - OB.Dal.insertData( - me.request.model, - data, - success, - handleError, - incremental, - dataLoaded - ); - } - } else { - success(); - } + + params._data = data; + params._model = me.request.model; + params._lastUpdated = lastUpdated; + params._totalRows = totalRows; + functionSave(params, success, errorCallback); }, function(data) { OB.UTIL.Debug.execute(function() { @@ -855,6 +831,14 @@ return; } }); + OB.DS.masterdataBackgroundModels = {}; + + OB.info( + OB.I18N.getLabel('OBMOBC_MasterdataRequestError') + + '. URL which failed: ' + + me.request.source + ); + OB.UTIL.showI18NWarning('OBMOBC_MasterdataRequestError'); if ( data && data.exception && @@ -877,6 +861,172 @@ ); }; + const doModelDataSave = function(params, success, handleError) { + const offset = params._offset; + const data = params._data; + const model = params._model; + if (model && !model.prototype.online) { + if (offset === 0) { + OB.Dal.initCache(model, data, success, handleError, incremental); + } else { + OB.Dal.insertData( + model, + data, + success, + handleError, + incremental, + dataLoaded + ); + } + } else { + success(); + } + }; + + const doModelDataSaveInRAM = function(params, success, handleError) { + const data = params._data; + const limit = params._limit; + const currentLength = data.length; + const backgroundLimit = OB.MobileApp.model.hasPermission( + 'OBMOBC_BackgroundMasterdataMaxSize', + true + ) + ? OB.MobileApp.model.hasPermission( + 'OBMOBC_BackgroundMasterdataMaxSize', + true + ) + : limit; + if ( + OB.DS.masterdataBackgroundModels['totalLength'] + currentLength > + backgroundLimit + ) { + OB.info( + 'Failed to do masterdata refresh in background because exceeds the limit of data. Trying normal refresh.' + ); + OB.UTIL.localStorage.setItem('neededForeGroundMasterDataRefresh'); + OB.UTIL.refreshMasterDataForeground(); + OB.DS.masterdataBackgroundModels = {}; + return; + } + if (!OB.DS.masterdataBackgroundModels.hasOwnProperty(me.request.source)) { + OB.DS.masterdataBackgroundModels[me.request.source] = {}; + OB.DS.masterdataBackgroundModels[me.request.source]['data'] = []; + } + + OB.DS.masterdataBackgroundModels[me.request.source]['data'] = [ + ...OB.DS.masterdataBackgroundModels[me.request.source]['data'], + ...params._data + ]; + + OB.DS.masterdataBackgroundModels[me.request.source]['model'] = + params._model; + OB.DS.masterdataBackgroundModels[me.request.source]['lastUpdated'] = + params._lastUpdated; + OB.DS.masterdataBackgroundModels[me.request.source]['totalRows'] = + params._totalRows; + + OB.DS.masterdataBackgroundModels[me.request.source]['lastUpdated'] = + me.request.lastUpdated; + + if (!OB.DS.masterdataBackgroundModels.hasOwnProperty('totalLength')) { + OB.DS.masterdataBackgroundModels['totalLength'] = 0; + } + OB.DS.masterdataBackgroundModels['totalLength'] += currentLength; + success(); + }; + + const doModelReadFromRAM = function(params, functionSave, errorCallback) { + if ( + OB.DS.masterdataBackgroundModels[me.request.source]['data'].length === 0 + ) { + me.trigger('ready'); + return; + } + let parameters = {}; + parameters._data = + OB.DS.masterdataBackgroundModels[me.request.source]['data']; + parameters._model = + OB.DS.masterdataBackgroundModels[me.request.source]['model']; + const lastUpdated_ = + OB.DS.masterdataBackgroundModels[me.request.source]['lastUpdated']; + const totalRows = + OB.DS.masterdataBackgroundModels[me.request.source]['totalRows']; + parameters._offset = 0; // in background all the pages are concatenated into one + + const success = function() { + OB.info( + '[sdreresh-' + + (incremental ? 'inc' : 'full') + + '] The model ' + + me.request.model.prototype.modelName + + ' has finished saving in db with a total of ' + + parameters._data.length + + ' records. ' + ); + updateModelLastUpdatedTimestamp( + lastUpdated_, + parameters._data, + totalRows + ); + me.trigger('ready'); + }; + functionSave(parameters, success, errorCallback); + }; + + handleIncrementalRequest = function( + limit, + offset, + params, + incremental, + lastId, + background + ) { + params = params || {}; + params._limit = limit; + params._offset = offset; + params._count = OB.UTIL.localStorage.getItem( + 'recordsFromBackendFor' + me.request.model.prototype.modelName + ) + ? parseInt( + OB.UTIL.localStorage.getItem( + 'recordsFromBackendFor' + me.request.model.prototype.modelName + ), + 10 + ) + : 0; + params._isMasterdata = true; + params.overrideDefaultTimeout = true; + params.lastId = lastId; + params.incremental = incremental; + + if (background === undefined) { + // foreground + doModelRequest( + params, + function(params, successCallback, errorCallback) { + doModelDataSave(params, successCallback, errorCallback); + }, + handleError + ); + } else if (background === 'background-request') { + doModelRequest( + params, + function(params, successCallback, errorCallback) { + doModelDataSaveInRAM(params, successCallback, errorCallback); + }, + handleError + ); + } else if (background === 'background-save') { + doModelReadFromRAM( + params, + function(params, successCallback, errorCallback) { + doModelDataSave(params, successCallback, errorCallback); + }, + handleError + ); + } + }; + this.cache = null; var lastId = null; // First request don't have lastId handleIncrementalRequest( @@ -888,7 +1038,8 @@ 0, params, incremental, - lastId + lastId, + background ); }; diff -r 0998deaab73b web/org.openbravo.mobile.core/source/model/ob-terminal-model.js --- a/web/org.openbravo.mobile.core/source/model/ob-terminal-model.js Thu Sep 05 07:49:00 2019 +0200 +++ b/web/org.openbravo.mobile.core/source/model/ob-terminal-model.js Fri Sep 06 11:40:56 2019 +0200 @@ -2089,7 +2089,7 @@ OB.UTIL.showLoading(false); }, - loadModels: function(windows, incremental, callback) { + loadModels: function(windows, incremental, parentCallback, background) { var i, j, windowName, @@ -2101,6 +2101,16 @@ c, path; + const callback = function() { + OB.info( + '[sdrefresh] Finished loading models ' + + (incremental ? 'incrementally' : 'full') + + '.' + + (background ? ' (' + background + ' )' : '') + ); + parentCallback(); + }; + if (OB.MobileApp.model.get('loggedOffline')) { if (callback instanceof Function) { callback(); @@ -2118,7 +2128,8 @@ OB.info( '[sdrefresh] Load models ' + (incremental ? 'incrementally' : 'full') + - '.' + '.' + + (background ? ' (' + background + ' )' : '') ); for (i = 0; i < windows.length; i++) { @@ -2160,9 +2171,20 @@ _.extend(datasources, Backbone.Events); - OB.debug('[sdrefresh] window: ' + windowName); + OB.debug( + '[sdrefresh] window: ' + + windowName + + (background ? '. (' + background + ' )' : '') + ); - OB.Dal.loadModels(false, datasources, null, incremental, callback); + OB.Dal.loadModels( + false, + datasources, + null, + incremental, + callback, + background + ); this.postLoadModels(); }, 41027-incrementalRefresh-posterminal-18q3-newFormatter-simpleQuotes.diff [^] (6,518 bytes) 2019-09-06 11:49 [Show Content] [Hide Content] diff -r f2a485fa1188 web/org.openbravo.retail.posterminal/js/utils/ob-utilitiesuipos.js --- a/web/org.openbravo.retail.posterminal/js/utils/ob-utilitiesuipos.js Thu Sep 05 07:35:25 2019 +0200 +++ b/web/org.openbravo.retail.posterminal/js/utils/ob-utilitiesuipos.js Fri Sep 06 11:46:55 2019 +0200 @@ -11,6 +11,9 @@ OB.UTIL = window.OB.UTIL || {}; +OB.UTIL.masterdataRefreshStatus = ''; +OB.UTIL.backgroundMasterdataRefreshEnabled; + OB.UTIL.sendLastTerminalStatusValues = function(callback) { var process = new OB.DS.Process( 'org.openbravo.retail.posterminal.process.LastTerminalStatusTimestamps' @@ -677,12 +680,53 @@ }; OB.UTIL.checkRefreshMasterData = function() { + // this code is called on: + // - ticket close + // - timeout of force refresh time + // - window navigation if ( OB.MobileApp.model.get('refreshMasterdata') === true && OB.UTIL.refreshMasterDataGetProperty('allowedIncrementalRefresh') ) { - OB.UTIL.clearFlagAndTimersRefreshMasterData(); - OB.UTIL.refreshMasterData(); + if ( + OB.UTIL.backgroundMasterdataIsEnabled() && + !OB.UTIL.localStorage.getItem('neededForeGroundMasterDataRefresh') + ) { + // background + // this is the save, the request was called in OB.UTIL.loadModelsIncFunc + if (OB.UTIL.masterdataRefreshStatus !== 'background-request-finished') { + OB.info( + "Cannot start masterdata save because the espected status was 'background-request-finished', but it was: " + + OB.UTIL.masterdataRefreshStatus + ); + } else { + OB.UTIL.clearFlagAndTimersRefreshMasterData(); + if (OB.DS.masterdataBackgroundModels.totalLength > 0) { + OB.UTIL.refreshMasterDataInBackgroundSave(); + } else { + OB.info('No updates in the masterdata.'); + } + } + } else { + // foreground + if (OB.UTIL.localStorage.getItem('neededForeGroundMasterDataRefresh')) { + OB.info( + 'Detected that previous masterdata refresh in background has fail because execeeds the limit of data. Trying normal refresh.' + ); + } + if ( + OB.UTIL.masterdataRefreshStatus !== '' && + OB.UTIL.masterdataRefreshStatus !== 'background-request-finished' + ) { + OB.info( + "Cannot start masterdata refresh in foreground because the espected status was '' or 'background-request-finished', but it was: " + + OB.UTIL.masterdataRefreshStatus + ); + } else { + OB.UTIL.clearFlagAndTimersRefreshMasterData(); + OB.UTIL.refreshMasterDataForeground(); + } + } } }; @@ -695,7 +739,56 @@ } }; -OB.UTIL.refreshMasterData = function() { + +OB.UTIL.refreshMasterDataInBackgroundRequest = function() { + if ( + OB.UTIL.masterdataRefreshStatus !== '' && + OB.UTIL.masterdataRefreshStatus !== 'background-request-finished' + ) { + OB.info( + 'Cannot start the masterdata requests because the expected status was "" or "background-request-finished" but it was: ' + + OB.UTIL.masterdataRefreshStatus + ); + return; + } + OB.UTIL.masterdataRefreshStatus = 'background-request-started'; + OB.DS.masterdataBackgroundModels = {}; + OB.MobileApp.model.loadModels( + null, + true, + function() { + OB.UTIL.masterdataRefreshStatus = 'background-request-finished'; + }, + 'background-request' + ); +}; + +OB.UTIL.refreshMasterDataInBackgroundSave = function() { + OB.UTIL.masterdataRefreshStatus = 'background-save-started'; + if (OB.UTIL.RfidController.isRfidConfigured()) { + OB.UTIL.RfidController.disconnectRFIDDevice(); + } + OB.UTIL.startLoadingSteps(); + OB.MobileApp.model.set('isLoggingIn', true); + OB.UTIL.showLoading(true); + OB.MobileApp.model.loadModels( + null, + true, + function() { + OB.UTIL.masterdataRefreshStatus = ''; + OB.DS.masterdataBackgroundModels = {}; + OB.UTIL.showLoading(false); + if (OB.UTIL.RfidController.isRfidConfigured()) { + OB.UTIL.RfidController.connectRFIDDevice(); + } + OB.MobileApp.model.set('isLoggingIn', false); + }, + 'background-save' + ); +}; + +OB.UTIL.refreshMasterDataForeground = function() { + OB.DS.masterdataBackgroundModels = {}; OB.MobileApp.model.set('secondsToRefreshMasterdata', 3); var counterIntervalId = null; counterIntervalId = setInterval(function() { @@ -704,6 +797,7 @@ OB.MobileApp.model.get('secondsToRefreshMasterdata') - 1 ); if (OB.MobileApp.model.get('secondsToRefreshMasterdata') === 0) { + OB.UTIL.masterdataRefreshStatus = 'foreground-started'; OB.MobileApp.model.set('refreshMasterdataShowPopup', false); clearInterval(counterIntervalId); if (OB.UTIL.RfidController.isRfidConfigured()) { @@ -718,6 +812,8 @@ OB.UTIL.RfidController.connectRFIDDevice(); } OB.MobileApp.model.set('isLoggingIn', false); + OB.UTIL.localStorage.removeItem('neededForeGroundMasterDataRefresh'); + OB.UTIL.masterdataRefreshStatus = ''; }); } }, 1000); @@ -800,8 +896,15 @@ OB.info(msg); OB.UTIL.showWarning(msg); } + if ( + OB.UTIL.backgroundMasterdataIsEnabled() && + !OB.UTIL.localStorage.getItem('neededForeGroundMasterDataRefresh') + ) { + OB.UTIL.refreshMasterDataInBackgroundRequest(); + } OB.MobileApp.model.set('refreshMasterdata', true); if (!OB.UTIL.isNullOrUndefined(minShowIncRefresh) && minShowIncRefresh >= 0) { + // Forced refresh by timeout, ticket close also calls to checkRefreshMasterData var noActivityTimeout = OB.MobileApp.model.get( 'refreshMasterdataNoActivityTimeout' ); @@ -1164,3 +1267,27 @@ ); } }; + +OB.UTIL.backgroundMasterdataIsEnabled = function() { + if (OB.UTIL.backgroundMasterdataRefreshEnabled === undefined) { + let preferenceValue = OB.MobileApp.model.hasPermission( + 'OBMOBC_BackgroundMasterdataMaxSize', + true + ); + if ( + !preferenceValue || + (preferenceValue && !isNaN(preferenceValue) && preferenceValue >= 1) + ) { + OB.UTIL.backgroundMasterdataRefreshEnabled = true; + } else { + OB.UTIL.backgroundMasterdataRefreshEnabled = false; + if (isNaN(preferenceValue)) { + OB.warn( + 'OBMOBC_BackgroundMasterdataMaxSize has a value not numeric: ' + + preferenceValue + ); + } + } + } + return OB.UTIL.backgroundMasterdataRefreshEnabled; +}; \ No newline at end of file | |||||||
Relationships [ Relation Graph ] [ Dependency Graph ] | |||||||||||||||||||||||||||||||||||||||||||
|
Notes | |
(0113910) hgbot (developer) 2019-08-08 16:41 |
Repository: tools/automation/pi-mobile Changeset: 56e61a198f644b6b867f172d681f49b9a2df17e6 Author: Gorka Gil <gorka.gil <at> openbravo.com> Date: Wed Jul 31 19:28:15 2019 +0200 URL: http://code.openbravo.com/tools/automation/pi-mobile/rev/56e61a198f644b6b867f172d681f49b9a2df17e6 [^] Related to issue 41027: added masterdata refresh tests and fix old ones Create new tests for play with the preference of masterdata background limit. Old tests are checking that the popup of masterdata appears, changed them to check the lastTimestamp to check that the update has happen Removes the statis waits of 2 mins, and call directly to the functions that are executed after the first timeout happends, and when the second timeout happen. Added tests to wait the timers to do the refresh masterdata, but only 2 and without higvol, so uses as less as possible time. Added api to work with the refresh masterdata to mobileCoreTerminalHelper Added api to set and remove preferences. --- M src-test/org/openbravo/test/mobile/retail/extmodules/selenium/terminals/WebPOSExtModulesLoyaltyTerminalHelper.java M src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/cashup/I38194_ResfreshMasterData.java M src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/selfcheckout/I38194_SCORefreshMasterData.java M src-test/org/openbravo/test/mobile/retail/mobilecore/selenium/terminals/MobileCoreTerminalHelper.java M src-test/org/openbravo/test/mobile/retail/pack/selenium/terminals/WebPOSTerminalHelper.java M src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/masterDataRefresh/I38194_ResfreshMasterDataCashManagement.java M src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/masterDataRefresh/I38194_ResfreshMasterDataCashUp.java M src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/masterDataRefresh/I38194_ResfreshMasterDataPointOfSale.java M src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/orderselector/VerifyOrderSelector.java M src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I30382_MasterDataUpdatedWithIncrementalRefresh.java M src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I34868_ResetCacheModelAfterIncrementalRefresh.java A src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/selfcheckout/BaseSCOMasterDataRefreshTests.java A src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/masterDataRefresh/BaseMasterDataRefreshTests.java A src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/masterDataRefresh/I41027_ResfreshMasterDataInBackground.java A src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/masterDataRefresh/ResfreshMasterDataOnTimer.java --- |
(0113911) hgbot (developer) 2019-08-08 16:41 |
Repository: tools/automation/pi-mobile Changeset: 970006e75a7a5389bcf1afdd68206e81ac700824 Author: Gorka Gil <gorka.gil <at> openbravo.com> Date: Thu Aug 08 16:40:22 2019 +0200 URL: http://code.openbravo.com/tools/automation/pi-mobile/rev/970006e75a7a5389bcf1afdd68206e81ac700824 [^] Related to issue 41027: disable masterdata background tests till they are stable --- M src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/masterDataRefresh/I41027_ResfreshMasterDataInBackground.java --- |
(0113913) hgbot (developer) 2019-08-08 16:41 |
Repository: erp/pmods/org.openbravo.mobile.core Changeset: 74cff7c7a4469593b37761ca694e2977c3a141ae Author: Gorka Gil <gorka.gil <at> openbravo.com> Date: Tue Aug 06 15:09:17 2019 +0200 URL: http://code.openbravo.com/erp/pmods/org.openbravo.mobile.core/rev/74cff7c7a4469593b37761ca694e2977c3a141ae [^] Related to issue 41027: Create modulescript to mantain refresh on login in existing instances --- A src-util/modulescript/src/org/openbravo/mobile/core/modulescript/MantainMasterdataRefreshBehaviour41027.java A src-util/modulescript/src/org/openbravo/mobile/core/modulescript/MantainMasterdataRefreshBehaviour41027_Data.xsql A src-util/modulescript/src/src/org/openbravo/mobile/core/modulescript/MantainMasterdataRefreshBehaviour41027Data.java --- |
(0113914) hgbot (developer) 2019-08-08 16:41 |
Repository: erp/pmods/org.openbravo.mobile.core Changeset: 86b8435e3609dc11c611a20a563becfd68611616 Author: Gorka Gil <gorka.gil <at> openbravo.com> Date: Wed Jul 31 17:55:38 2019 +0200 URL: http://code.openbravo.com/erp/pmods/org.openbravo.mobile.core/rev/86b8435e3609dc11c611a20a563becfd68611616 [^] Fixes issue 41027: Implement masterdata refresh in background - Set as default the preference that skip the refresh in logins and F5. Also created a modulescript to mantain old behaviour in current instances. - split the code inside handleIncremental into 2 functions: - doModelRequest - doModelDataSave - Also added 2 new functions: - doModelReadFromRAM - doModelDataSaveInRAM These functions save in ram the request and read from ram to pass to the save in db. In ram is saved all the needed things so the save code in db is exactly the same as before. Changes in behaviour: There is a timeout by default 60 mins, that calls to OB.UTIL.loadModelsIncFunc() - old: it saves in local storage that is needed to do the refresh - new: start the request of models in background When a ticket is closed, or when the other timeout (by default 5 mins) finish, or when there is navigation to another window, it calls to OB.UTIL.checkRefreshMasterData(): - old: a popup with a countdwon of 3 secs starts and if not cancelled a foreground refresh starts - new: starts a foreground save from ram to db Others: - The backgorund refresh if reach a limit, launches the old refresh (foreground one). In this case is saved in localstorage to avoid any other background refresh till a foreground one has happen. The models loaded by the backgorund request don't update the timestamp used to know if a model has been updated, so if the 10th model exceeds the limit and normal one is used the first nine models are requested again and no data is lost. - Since now the request and save are independent, there are protections to not start the save in db before the the requests has finish. Also to protect that requests, save and foreground refresh don't execute in parallel. This protections are saved in ram so a F5 will delete them, intended to not let the refresh blocked if presed F5 in the midle of process. - If no update in any model, it will do nothing, not even show the scrim of showloading. Also if a model don't have updates, it is skipped. Added a message at the end of the process to know that has finish, since skipped models don't show a line in the console. - Reduced the console messages, since the console messages makes the process much slower. - Add missing return in triggerReady first if, so don't call twice to sucess callback (dalLoadModelsCallback). --- M src-db/database/sourcedata/AD_MESSAGE.xml M src-db/database/sourcedata/AD_PREFERENCE.xml M src-db/database/sourcedata/AD_REF_LIST.xml M web/org.openbravo.mobile.core/source/data/ob-dal.js M web/org.openbravo.mobile.core/source/data/ob-datasource.js M web/org.openbravo.mobile.core/source/model/ob-terminal-model.js --- |
(0113915) hgbot (developer) 2019-08-08 16:41 |
Repository: erp/pmods/org.openbravo.retail.posterminal Changeset: 8a8262d9cfe88ad8193b5a1d3468cc8e19419e4f Author: Gorka Gil <gorka.gil <at> openbravo.com> Date: Wed Jul 31 17:54:03 2019 +0200 URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/rev/8a8262d9cfe88ad8193b5a1d3468cc8e19419e4f [^] Related to issue 41027: Implement masterdata refresh in background --- M web/org.openbravo.retail.posterminal/js/utils/ob-utilitiesuipos.js --- |
(0114027) hgbot (developer) 2019-08-16 08:09 |
Repository: erp/pmods/org.openbravo.mobile.core Changeset: a77df10e67664a12795082c652f20e4b53ff7918 Author: Antonio Moreno Perez <antonio.moreno <at> openbravo.com> Date: Fri Aug 16 08:09:13 2019 +0200 URL: http://code.openbravo.com/erp/pmods/org.openbravo.mobile.core/rev/a77df10e67664a12795082c652f20e4b53ff7918 [^] Related to issue 41027. Show which model failed in case there was a failure. --- M web/org.openbravo.mobile.core/source/data/ob-datasource.js --- |
Issue History | |||
Date Modified | Username | Field | Change |
2019-06-04 18:50 | gorka_gil | New Issue | |
2019-06-04 18:50 | gorka_gil | Assigned To | => gorka_gil |
2019-06-04 18:50 | gorka_gil | Triggers an Emergency Pack | => No |
2019-06-04 18:55 | gorka_gil | Status | new => scheduled |
2019-06-05 13:30 | gorka_gil | Relationship added | related to 0040846 |
2019-07-22 16:46 | rafaroda | Issue Monitored: rafaroda | |
2019-08-07 13:57 | gorka_gil | Relationship added | related to 0041588 |
2019-08-08 16:41 | hgbot | Checkin | |
2019-08-08 16:41 | hgbot | Note Added: 0113910 | |
2019-08-08 16:41 | hgbot | Checkin | |
2019-08-08 16:41 | hgbot | Note Added: 0113911 | |
2019-08-08 16:41 | hgbot | Checkin | |
2019-08-08 16:41 | hgbot | Note Added: 0113913 | |
2019-08-08 16:41 | hgbot | Checkin | |
2019-08-08 16:41 | hgbot | Note Added: 0113914 | |
2019-08-08 16:41 | hgbot | Status | scheduled => resolved |
2019-08-08 16:41 | hgbot | Resolution | open => fixed |
2019-08-08 16:41 | hgbot | Fixed in SCM revision | => http://code.openbravo.com/erp/pmods/org.openbravo.mobile.core/rev/86b8435e3609dc11c611a20a563becfd68611616 [^] |
2019-08-08 16:41 | hgbot | Checkin | |
2019-08-08 16:41 | hgbot | Note Added: 0113915 | |
2019-08-16 08:09 | hgbot | Checkin | |
2019-08-16 08:09 | hgbot | Note Added: 0114027 | |
2019-08-16 08:10 | marvintm | Review Assigned To | => marvintm |
2019-08-16 08:10 | marvintm | Status | resolved => closed |
2019-08-16 08:10 | marvintm | Fixed in Version | => RR19Q4 |
2019-08-27 11:29 | gorka_gil | File Added: 41027-incrementalRefresh-mobilecore-18q3-newFormatter.diff | |
2019-08-27 11:29 | gorka_gil | File Added: 41027-incrementalRefresh-posterminal-18q3-newFormatter.diff | |
2019-08-30 15:11 | samuel_nicuesa | File Added: mobCore_OldFormater_1.diff | |
2019-08-30 15:11 | samuel_nicuesa | File Added: mobCore_OldFormater_2.diff | |
2019-08-30 15:11 | samuel_nicuesa | File Deleted: mobCore_OldFormater_1.diff | |
2019-08-30 15:11 | samuel_nicuesa | File Deleted: mobCore_OldFormater_2.diff | |
2019-08-30 15:12 | samuel_nicuesa | File Added: mobCore_OldFormatter_1.diff | |
2019-08-30 15:12 | samuel_nicuesa | File Added: mobCore_OldFormatter_2.diff | |
2019-08-30 15:12 | samuel_nicuesa | File Added: mobCore_OldFormatter_3.diff | |
2019-08-30 15:13 | samuel_nicuesa | File Added: posterminal_OldFormatter.diff | |
2019-09-06 11:07 | gorka_gil | File Added: 41027-incrementalRefresh-mobilecore-18q3-newFormatter-simpleQuotes.diff | |
2019-09-06 11:07 | gorka_gil | File Added: 41027-incrementalRefresh-posterminal-18q3-newFormatter-simpleQuotes.diff | |
2019-09-06 11:48 | gorka_gil | File Deleted: 41027-incrementalRefresh-mobilecore-18q3-newFormatter-simpleQuotes.diff | |
2019-09-06 11:48 | gorka_gil | File Deleted: 41027-incrementalRefresh-posterminal-18q3-newFormatter-simpleQuotes.diff | |
2019-09-06 11:49 | gorka_gil | File Added: 41027-incrementalRefresh-mobilecore-18q3-newFormatter-simpleQuotes.diff | |
2019-09-06 11:49 | gorka_gil | File Added: 41027-incrementalRefresh-posterminal-18q3-newFormatter-simpleQuotes.diff | |
2019-09-20 10:20 | gorka_gil | Relationship added | related to 0041831 |
2019-11-04 11:22 | rafaroda | Relationship added | related to 0041832 |
2021-12-07 11:52 | shuehner | Relationship added | related to 0048198 |
2022-01-19 18:17 | gorka_gil | Relationship added | related to 0048422 |
Copyright © 2000 - 2009 MantisBT Group |