Event sync frequency, infinite loop in afterSave

does this seem familiar to you?

{"_objCount":130229,"className":"Created","id":"ziSlwXdKghmOU5Nj6qdrhxU5"} 

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"));
  logger.info(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();
  logger.info(results);
 
  if(results){
    
 
   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();
  }else{
  	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:

{"_objCount":95093,"className":"Created","id":"QlxQItxuCpnrE8aIYpWRVSZ7"} 
{"_objCount":95095,"className":"Created","id":"kp6B3RZ3grGsjsfbOaRYZL3l"} 
{"_objCount":95096,"className":"Created","id":"XBp1yO5iepGMTIcTyK0sGlkA"}

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"}

Can you see anything in your logs in dashboard or you have a blank white page?

Yes, I didn’t want to add another issue to the topic but the logs appear to be broken.

instead of logger.info(uid); you should use logger.info(JSON.stringify(uid));
that would be for every logger.info that you use, you may see the logs after that and after you reset the server again

1 Like