How to speed up the ipfs data retrieval?

Please consider the following code which retrieves json data from some IPFS hashes:

const IPFS      = require('ipfs-mini');
const ipfs      = new IPFS({ host: '', port: 5001, protocol: 'https' });

var mergeJSON   = require("merge-json");   

async function mergeJSONs( hashArry ){

    var mergedJSON  = {}
    var dataArray   = [];

    for(var hash of hashArry){
            var data = await ipfsRetrieve(hash)

         mergedJSON  = mergeJSON.merge(mergedJSON, JSON);


function ipfsRetrieve( ipfsHash ){
return new Promise( function( resolve, reject ) {
    ipfs.catJSON( ipfsHash, (err, result) => {
        if (err){                

Now, when I call:

var hashArray   = [ "Qmds...nZTDcbbfgcWMKPo6qfi",
mergeJSONs( hashArray )

It takes me some sensible seconds to see the result.How can I speed up this IPFS retrieving specially for large number of hashes?

One idea is to retrieve in parallel and skip the dataArray.

const dataPromises = => ipfsRetrieve(hash));
for (const dataPromise of dataPromises) {
  const dataJSON = await dataPromise;
  mergedJSON = mergeJSON.merge(mergedJSON, dataJSON);

Of course this could cause a big waste: if a failure happens early, it will still retrieve the rest.

1 Like

Thanks for your attention and reply.

I used your suggestion, but again the time consuming part is still getting data from IPFS through hashes. Is there any way for accelerating this?