Please increase your query limit, please

Hi @mauvanceb , since the code I wrote queries the items in serial, it will not start the next query untill it finishes the previous one, which can take a long time to query a big database since the server will terminate the process after 14 seconds.

To overcome this issue, we first need to know the actual number of the items we’re going to get, then use the JavaScript map() function to create an array of promises, then finally use Promise.all() to call the promises in parallel.

I’ll give you a simple example:

// This function will get the total number of items that match your criteria
function getTotalItems() {
    return wixData.query('col').eq('prop', value).count();
}

// This function will create an array of promises based on the total number
function getPromises(total) {
    // Getting the number of promises
    const number = total > 1000 ? ((total - total % 1000) / 1000) + 1 : 1;
    
    // Creating an array of numbers
    let numbers = [];
    for (let i = 0; i < number; i++) { numbers.push(i) }
    
    // Return an array of promises
    return numbers.map(num => {
        return new Promise((resolve, reject) => {
            // Create the query with your own filters, I'll use the simplest one
            const query = wixData.query('col1');
            query.limit(1000).skip(num * 1000).find().then(x => resolve(x.items))
        })
    })
}

// This is the main function that will execute everything
async function getItems() {
    try {
        const total = await getTotalItems();
        const promises = getPromises(total);
        
        // Call the promises in paralel.
        const raw_items = await Promise.all(promises);
        
        // Combine the items in one array.
        let items = [];
        for (arrayItems of raw_items) {
            items = items.concat(arrayItems);
        }
        
        // Return the final array.
        return Promise.resolve(items);
    } catch(err) {
        return Promise.reject(err);
    }
}

I haven’t tried it, so it might need a little bit tweaking, so let me know if you have any issues, and hope this helps.

Ahmad