Event sync frequency, infinite loop in afterSave

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

Where can I log the _objCount? So I can debug from my side

Thanks, I got rid of the logger all together and CPU is back to normal (20%) which is a step forward.
Still I can’t see the logs though

maybe you don’t have anything in logs yet if you removed all logger.info

When I try to access the log page It returns a black page:

Maybe the error in the console could help

can you add back your logger.info and this time using JSON.stringify?
what you get now as error should be fixed with a server restart

I added the logger printing a simple “Hello World” at the beginning of the afterSave cloud function

Moralis.Cloud.afterSave("FullyMintedNewNew", async (request) => {
  
  const logger = Moralis.Cloud.getLogger();
  logger.info("Hello World");
    
  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();

 
  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); 
   results.save();
   request.object.save();
    
  }else{
  	console.error("this teekey has no metadata yet");
  }
  
});

Now I can see the logs and looks like the afterSave function is being called multiple times:

Also CPU is back at 100% probably because of the loop

I guess because I’m altering the state of the class so the aftersave gets call continuously. I should put a condition to save just if the new fields are not present.

yep, you have to fix somehow that infinite loop

That seams to be fixed now. Thanks a lot for your patience!

2 Likes