4 Replies Latest reply: Dec 12, 2016 3:09 PM by Alexander Karlsson RSS

    Qliksense API - parallel asynchrounous data fetching using Promises

    Patric Amatulli

      Hi all,

       

      we have developed an extension and we have noticed that the extension are pretty slow during the data process fetching.
      We implemented a sequential data fetching process which takes approximately 20 seconds for fetching 60.000 rows (3 columns = 2 dimension + 1 measure).

       

      I was wondering if there is the possibility to use an asynchonous parallel data fetching mechanismus using promises using the backendapi from qlik.
      When I execute the code it raises always an exception when trying to load multiple requests at the same time, works fine when it is limited to 1 or 2.  Is this is a bug or it is simple not allowed to do it by the Qlik Engine?

       

      Any idea or hint would be very much appreciated :-) !

       

       function fetchData() {
            var columns = config.DATA_PER_ROW;  
            var totalheight = rowCount; 
            var pageheight = Math.floor(10000 / columns);  
            var numberOfPages = Math.ceil(totalheight / pageheight);  
            var qTotalData = [];
            var deferred = $.Deferred()
        
            var promises = Array.apply(null, Array(numberOfPages)).map(function(data, index) {  
                return backendApi.getData([{
                      qTop: (pageheight * index) + index,  
                      qLeft: 0,  
                      qWidth: columns,  
                      qHeight: pageheight,  
                      index: index  
                    }]); 
            }, this);         
      
      
            Promise.all(promises).then(function(data) {  
              var qsData = data[0];
                  for (var j=0; j<qsData.length; j++) {  
                      for (var k=0; k<qsData[j].qMatrix.length; k++) {                                                  
                          qTotalData.push(qsData[j].qMatrix[k])  
                      }  
                }  
                console.log(qTotalData);
                deferred.resolve(qTotalData); 
                  
            }).catch(function(error) { console.log(error)});   
        }
      
      
      
      
      


      The code raises a general exception (undefined) :-/.

       

      Cheers,

      Patric

        • Re: Qliksense API - parallel asynchrounous data fetching using Promises
          Patric Amatulli

          For all who are interested in:

           

          It seems that the getData() Method from the backendApi has a bug.

          I have used the model object instead and the getHyperCubeData method.

           

           var promises = Array.apply(null, Array(numberOfPages)).map(function(data, index) {  
          
          
                 var page = {  
                          qTop: (pageheight * index) + index,  
                          qLeft: 0,  
                          qWidth: columns,  
                          qHeight: pageheight,  
                          index: index  
                    };                                                                                             
                    return model.getHyperCubeData('/qHyperCubeDef', [page]);  
                }, this);      
                
                Promise.all(promises).then(function(data) {  
                    console.log(data);
                    for (var j=0; j<data.length; j++) {  
                          for (var k=0; k<data[j].qDataPages[0].qMatrix.length; k++) {                                                         
                              qTotalData.push(data[j].qDataPages[0].qMatrix[k])  
                          }  
                    } 
          

           

          Cheers,
          Patric