Event sync frequency, infinite loop in afterSave

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