Data query

How can i optimise my dataquery because it is taking longer when loading by when i check the in developer tools of my browser it seems most of the reosurces that i am fetching have been fetched my query is as below

const query = {
        organisationUnits: {
            resource: 'organisationUnits',
            params: {
                fields: ["*"],
                order: 'level',
            }
        }, dataElements: {
            resource: 'dataElements',
            params: {
                fields: ["*"]
            }
        },
        dataSets: {
            resource: 'dataSets',
            params: {
                fields: [
                    'name',
                    'id',
                    'organisationUnits(*)',
                    'periodType',
                    'dataSetElements(dataSet,dataElement(id,name,displayName,formName))'
                ]
            }
        },
        periodTypes: {
            resource: 'periodTypes'
        },
        dataStore: {
            resource: 'dataStore',
            params: {
                fields: ["*"]
            }
        }
    }```

Hi @Yambanso_Kausiwa

1- Instead of requesting all fields of a resource, specify only the fields that you need. This will reduce the amount of data transferred and also can speed up the response time.
2- Implement cache mechanism, this will improve overall performance of the application.
3- If these nested queries are not necessary for your use case, you can eliminate these, can can fetch the resources one by one.

Here is the optimized version of your query.

const query = {
    organisationUnits: {
        resource: 'organisationUnits',
        params: {
            fields: ['id', 'name'],
            order: 'level',
        },
    },
    dataElements: {
        resource: 'dataElements',
        params: {
            fields: ['id', 'name'],
        },
    },
    dataSets: {
        resource: 'dataSets',
        params: {
            fields: ['id', 'name', 'organisationUnits(id, name)', 'periodType'],
        },
    },
    periodTypes: {
        resource: 'periodTypes',
        params: {
            fields: ['id', 'name'],
        },
    },
    dataStore: {
        resource: 'dataStore',
        params: {
            fields: ['id', 'name'],
        },
    },
};

Let me know if the provided information is helpful.
Thanks