Event sync frequency, infinite loop in afterSave

Hi there,
I’m building a dApp using Moralis and one of the main feature is being able to mint and notify the user of the successful transaction on the UI.
I’m using your event sync feature to update the database once the transaction is received and confirmed.
However, the platform seem to be syncing very slowly, sometimes hours later of the confirmation I see on Rinkeby scan.
I was wondering if you could shine a light on the frequency of the sync between the chain and the moralis platform and suggest if there is a way to speed it up.
Is this delay only happening in the test network? Can it depend on the fact that the server CPU and ram shows 100% ? Non sure why that’s happening because I’m the only one testing the dApp at the moment and there are no many requests being sent.
Many thanks for your help,

Hi, can you share your server url?

here we go,
thanks heaps

does this seem familiar to you?


Yes, it’s one of the tables I created to store the NFT metadata

But there should be only 7 objects stored

Not sure if it helps but I’m using an aftersave cloud function to update the “Created” class after the “FullyMinted” class is synced

Moralis.Cloud.afterSave("FullyMinted", async (request) => {
  const logger = Moralis.Cloud.getLogger();
  const uid = parseInt(request.object.get("uid"));
  const q = new Moralis.Query("Created");
  q.equalTo("parentAddress", request.object.get("parentAddress"));
  q.equalTo("parentTokenID", request.object.get("parentTokenID"));
  var results = await q.first();
   request.object.set("gifUrl", results.get("gifUrl"));
   request.object.set("staticImageUrl", results.get("staticImageUrl"));
   request.object.set("parentAddress", results.get("parentAddress"));
   request.object.set("parentTokenID", results.get("parentTokenID"));
   request.object.set("parentNftImageUrl", results.get("parentNftImageUrl"));
   request.object.set("parentNftThumbUrl", results.get("parentNftThumbUrl"));
   results.set("minted", true); 
   await results.save();
   return await request.object.save();
  	console.error("this teekey has no metadata yet");

return await request.object.save(); may generate an infinite loop if afterSave will be called again

Thanks. I remove the return and tried to run the sync job but I still can’t see the old events.
Should I restart the server? Create a new sync event?

You can try to restart the server

I restarted and tried to sync again but no luck. I will try setting up new event sync with a new class

Once I create a new event sync it pulled all historical data and also was able to pull the first new mint very quickly. However the second time it didn’t work and it’s stuck again.
Is it possible the problem is related to the fact that I’m modifying the schema (adding extra fields) to the Class used for the sync event in the aftersave cloud function? Maybe I’m not supposed to do that

I still see things like {"_objCount":1642,"className":"Created","id":"wn3vwyRGuWUXkypGB6pRlmu9"}
It looks like you still have an infinite loop

same thing now with {"_objCount":10929,"className":"Created","id":"XBp1yO5iepGMTIcTyK0sGlkA"}

I removed all “await” from the afterSave function and it seems to be syncing now

Can you please let me know if you still see infinite loops going on? That will be obviously a concern in terms of performances

I still see them now:


What is _objCount? I can see those objects in the created Class but not sure what objCount means

it looks to be how many times that loop iterated, now it is {"_objCount":300728,"className":"Created","id":"QlxQItxuCpnrE8aIYpWRVSZ7"}