dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #42113
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21514: event-capture: meta-data loading performance improvement - WIP
------------------------------------------------------------
revno: 21514
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-12-22 14:18:43 +0100
message:
event-capture: meta-data loading performance improvement - WIP
modified:
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js 2015-12-21 16:42:10 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js 2015-12-22 13:18:43 +0000
@@ -33,7 +33,7 @@
dhis2.ec.store = new dhis2.storage.Store({
name: 'dhis2ec',
adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter],
- objectStores: ['programs', 'programStages', 'categories', 'geoJsons', 'optionSets', 'events', 'programValidations', 'programRules', 'programRuleVariables', 'programIndicators', 'ouLevels', 'constants']
+ objectStores: ['programs', 'geoJsons', 'optionSets', 'events', 'programValidations', 'programRules', 'programRuleVariables', 'programIndicators', 'ouLevels', 'constants']
});
(function($) {
@@ -154,8 +154,6 @@
promise = promise.then( getOrgUnitLevels );
promise = promise.then( getMetaPrograms );
promise = promise.then( getPrograms );
- //promise = promise.then( getProgramStages );
- //promise = promise.then( getCategories );
promise = promise.then( getMetaProgramValidations );
promise = promise.then( getProgramValidations );
promise = promise.then( getMetaProgramIndicators );
@@ -292,17 +290,18 @@
build.done(function() {
promise = promise.done( function () {
+ var _ids = null;
if( ids && ids.length > 0 ){
- var _ids = ids.toString();
+ _ids = ids.toString();
_ids = '[' + _ids + ']';
promise = promise.then( getAllPrograms( _ids ) );
}
- mainDef.resolve( programs, ids );
+ mainDef.resolve( programs, _ids );
} );
def.resolve();
}).fail(function(){
- mainDef.resolve( null );
+ mainDef.resolve( null, null );
});
builder.resolve();
@@ -341,11 +340,13 @@
}
function getOptionSets( programs )
-{
+{
if( !programs ){
return;
}
+ delete programs.programIds;
+
var mainDef = $.Deferred();
var mainPromise = mainDef.promise();
@@ -393,19 +394,20 @@
return mainPromise;
}
-function getMetaProgramValidations( programs )
-{
- return getD2MetaObject(programs, 'programValidations', '../api/programValidations.json', 'paging=false&fields=id,program[id]');
+function getMetaProgramValidations( programs, programIds )
+{
+ programs.programIds = programIds;
+ return getD2MetaObject(programs, 'programValidations', '../api/programValidations.json', 'paging=false&fields=id&filter=program.id:in:');
}
function getProgramValidations( programValidations )
-{
+{
return checkAndGetD2Objects( programValidations, 'programValidations', '../api/programValidations', 'fields=id,name,name,operator,rightSide[expression,description],leftSide[expression,description],program[id]');
}
function getMetaProgramIndicators( programs )
-{
- return getD2MetaObject(programs, 'programIndicators', '../api/programIndicators.json', 'paging=false&fields=id,program[id]');
+{
+ return getD2MetaObject(programs, 'programIndicators', '../api/programIndicators.json', 'paging=false&fields=id&filter=program.id:in:');
}
function getProgramIndicators( programIndicators )
@@ -414,8 +416,8 @@
}
function getMetaProgramRules( programs )
-{
- return getD2MetaObject(programs, 'programRules', '../api/programRules.json', 'paging=false&fields=id,program[id]');
+{
+ return getD2MetaObject(programs, 'programRules', '../api/programRules.json', 'paging=false&fields=id&filter=program.id:in:');
}
function getProgramRules( programRules )
@@ -425,7 +427,7 @@
function getMetaProgramRuleVariables( programs )
{
- return getD2MetaObject(programs, 'programRuleVariables', '../api/programRuleVariables.json', 'paging=false&fields=id,program[id]');
+ return getD2MetaObject(programs, 'programRuleVariables', '../api/programRuleVariables.json', 'paging=false&fields=id&filter=program.id:in:');
}
function getProgramRuleVariables( programRuleVariables )
@@ -435,38 +437,20 @@
function getD2MetaObject( programs, objNames, url, filter )
{
- if( !programs ){
+ if( !programs || !programs.programIds){
return;
}
+ //console.log('programs.programIds: ', programs.programIds);
+ filter = filter + programs.programIds;
var def = $.Deferred();
- var programIds = [];
- _.each( _.values( programs ), function ( program ) {
- if( program.id ) {
- programIds.push( program.id );
- }
- });
-
$.ajax({
url: url,
type: 'GET',
data:filter
- }).done( function(response) {
- var objs = [];
- _.each( _.values( response[objNames]), function ( o ) {
- if( o &&
- o.id &&
- o.program &&
- o.program.id &&
- programIds.indexOf( o.program.id ) !== -1) {
-
- objs.push( o );
- }
-
- });
-
- def.resolve( {programs: programs, self: objs} );
+ }).done( function(response) {
+ def.resolve( {programs: programs, self: response[objNames], programIds: programs.programIds} );
}).fail(function(){
def.resolve( null );
@@ -476,8 +460,8 @@
}
function checkAndGetD2Objects( obj, store, url, filter )
-{
- if( !obj || !obj.programs || !obj.self ){
+{
+ if( !obj || !obj.programs || !obj.self || !obj.programIds){
return;
}
@@ -490,13 +474,14 @@
var builder = $.Deferred();
var build = builder.promise();
+ var ids = [];
_.each( _.values( obj.self ), function ( obj) {
build = build.then(function() {
var d = $.Deferred();
var p = d.promise();
dhis2.ec.store.get(store, obj.id).done(function(o) {
- if(!o) {
- promise = promise.then( getD2Object( obj.id, store, url, filter, 'idb' ) );
+ if(!o){
+ ids.push( obj.id );
}
d.resolve();
});
@@ -508,7 +493,15 @@
build.done(function() {
def.resolve();
promise = promise.done( function () {
- mainDef.resolve( obj.programs );
+
+ if( ids && ids.length > 0 ){
+ var _ids = ids.toString();
+ _ids = '[' + _ids + ']';
+ filter = filter + '&filter=id:in:' + _ids + '&paging=false';
+ promise = promise.then( getAllD2Objects( store, url, filter ) );
+ }
+
+ mainDef.resolve( obj.programs, obj.programIds );
} );
}).fail(function(){
mainDef.resolve( null );
@@ -519,6 +512,22 @@
return mainPromise;
}
+
+function getAllD2Objects( store, url, filter )
+{
+ return function() {
+ return $.ajax( {
+ url: url,
+ type: 'GET',
+ data: filter
+ }).done( function( response ){
+ if(response[store]){
+ dhis2.ec.store.setAll( store, response[store] );
+ }
+ });
+ };
+}
+
function getD2Objects(store, objs, url, filter)
{
var def = $.Deferred();
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js 2015-12-01 14:01:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js 2015-12-22 13:18:43 +0000
@@ -10,7 +10,7 @@
var store = new dhis2.storage.Store({
name: 'dhis2ec',
adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter],
- objectStores: ['programs', 'programStages', 'categories', 'geoJsons', 'optionSets', 'events', 'programValidations', 'programRules', 'programRuleVariables', 'programIndicators', 'ouLevels', 'constants']
+ objectStores: ['programs', 'geoJsons', 'optionSets', 'events', 'programValidations', 'programRules', 'programRuleVariables', 'programIndicators', 'ouLevels', 'constants']
});
return{
currentStore: store