cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

How to fetch data in chunks with SearchThingsByTemplate method

Level 5

How to fetch data in chunks with SearchThingsByTemplate method

Hi,

 

I am using SearchThingsByTemplate method to get all remote things data from a server to my system.

The data is so huge and I am getting timeout while fetching the data.

Is there any way to fetch the data in chunks.

 

Currently I am using below code to get all data together. 

 

var Entityresult = Subsystems["PlatformSubsystem"].GetEntityCount({ type: "Things" });
var maximumThingsCount= Entityresult.count;

var params =

{
maxItems: maximumThingsCount,
nameMask: undefined,
query: undefined,
thingTemplate: 'ThingworxTemplate',
tags: 'TWX:RuntimeData'
};


var result = Resources["SearchFunctions"].SearchThingsByTemplate(params);

 

 With the same code if I am getting 2000 Things together. How can I get the data in batch of 100 ?

 

Thanks

1 REPLY

Re: How to fetch data in chunks with SearchThingsByTemplate method

There isn't an standard way of doing it.

 

But, when you say from your server to your system what does you mean? Becouse the cose you are showing here it's Javascript server side snippet which runs on the same server.

 

Few recomendations:

Whenever you can use ThingTemplates["ThingworxTemplate"].QueryImplementingThings(); which it's a way faster than SearchThingsByTemplate one. For instance this code it's faster than yours:

var result = ThingTemplates["ThingworxTemplate"].QueryImplementingThings({
        maxItems: undefined /* NUMBER */,
        nameMask: undefined /* STRING */,
        query: undefined /* QUERY */,
        tags: "TWX:RuntimeData"
    });

Then the speed problem it's on the connection side and you must transfer data in chunks you will need to implement a custom service on source where you pass PageNumber and PageSize and return the desired rows.

 

Something Like

var thingTemplateName = "ThingworxTemplate";
var taggedWith = "TWX:RuntimeData"    
var Entityresult = Subsystems["PlatformSubsystem"].GetEntityCount({ type: "Things" });
    var maximumThingsCount= Entityresult.count;
    var startItems = PageNumber*PageSize;
    var maxItems = startItems+PageSize;
    var tempResult = ThingTemplates[thingTemplateName].QueryImplementingThings({
        maxItems: maximumThingsCount,
        nameMask: undefined /* STRING */,
        query: undefined /* QUERY */,
        tags: taggedWith
    });

    result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
        infoTableName : "InfoTable",
        dataShapeName : "RootEntityList"
    });

    for(var i=startItems;(i<maxItems)&&(i<tempResult.rows.length);i++) {
        result.AddRow(tempResult.rows[i]);
    }