Why are cloud function so slow?

I’ve been working on a nft marketplace and it required to listen to events on contract. Whenever the event is fired I check for its confirmation like this:
const confirmed = request.object.get("confirmed");
and then there is an if statement that fires when confirmed is true like this:

if (confirmed) {
        logger.info("Found item!"); .... 

But the issue is it takes almost 10-15 mins between the firing of actual event and calling of if statement.

Any suggestions for what is going wrong?

15 minutes seems a lot. On what chain does that happen?

Mumbai testnet
80001

code goes like this :

Moralis.Cloud.afterSave("ItemListed", async(request) => {
    const confirmed = request.object.get("confirmed");
    const logger = Moralis.Cloud.getLogger();
    logger.info("Looking for confirmed TX...");
    if (confirmed) {
        logger.info("Found item!");
        const ActiveItem = Moralis.Object.extend("ActiveItem");
   ...

You can check in the database to see when it was created that row.

It should be faster than that in general.

See this is the complete code :

Moralis.Cloud.afterSave("ItemListed", async(request) => {
    const confirmed = request.object.get("confirmed");
    const logger = Moralis.Cloud.getLogger();
    logger.info("Looking for confirmed TX...");
    if (confirmed) {
        logger.info("Found item!");
        const ActiveItem = Moralis.Object.extend("ActiveItem");

        // In case of listing update, search for already listed ActiveItem and delete
        const query = new Moralis.Query(ActiveItem);
        query.equalTo("nftAddress", request.object.get("nftAddress"));
        query.equalTo("tokenId", request.object.get("tokenId"));
        query.equalTo("marketplaceAddress", request.object.get("address"));
        query.equalTo("seller", request.object.get("seller"));
        logger.info(`Marketplace | Query: ${query}`);
        const alreadyListedItem = await query.first();
        if (alreadyListedItem) {
            logger.info(`Deleting ${request.object.get("objectId")}`);
            await alreadyListedItem.destroy();
            logger.info(
                `Deleted item with tokenId ${request.object.get(
          "tokenId"
        )} at address ${request.object.get(
          "address"
        )} since the listing is being updated. `
            );
        }

        // Add new ActiveItem
        const activeItem = new ActiveItem();
        activeItem.set("marketplaceAddress", request.object.get("address"));
        activeItem.set("nftAddress", request.object.get("nftAddress"));
        activeItem.set("price", request.object.get("price"));
        activeItem.set("tokenId", request.object.get("tokenId"));
        activeItem.set("seller", request.object.get("seller"));
        logger.info(
            `Adding Address: ${request.object.get(
        "address"
      )} TokenId: ${request.object.get("tokenId")}`
        );
        logger.info("Saving...");
        await activeItem.save();
    }
});

I don’t know what you want me to see in that complete code, I assumed that this line

has a big delay from what you say

So, there are 2 tables listItems and ActiveItems. ListItems is updated when the event is fired.
But we are fetching objects from ActiveItems table which is updated when when the code inside of if statement runs.
And there comes the problem because if block is taking time to execute. And hence it takes time to add the entry in ActiveItems table.
I hope I explained the issue well

it is expected to be a few minutes delay for confirmed to be set, depending on chain and on how many transactions are made on that chain

you should receive faster the transaction without confirmed flag set to true

Doing this might leave a hole in the code, if in case transaction fails.
It will still show the entry in Activeitems.

I don’t understand what you mean. You have to be able to take in consideration a delay until the transaction is considered as confirmed.

Transaction confirmation does not take 10-15 mins. Right?

it depends on chain, on how active that chain is

Okay, I think I need to go through everything once more.

mumbai testnet does not take this much time. Sometimes may be but not always.