FatFractal customer forums



Author Topic: Retrieve Handler Issue  (Read 2461 times)

jonnycools

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Retrieve Handler Issue
« on: January 31, 2014, 03:24:43 PM »
I'm using a retrieve event handler to load transient properties: Like and Subscription. Both have references to the event as object.

When I attempt to access the BackReferences grabbag is the retrieve handler being executed?

I've tried several things but I'm lost.

Code: [Select]

CREATE HANDLER EventRetrievePost POST ON /Event Retrieve AS javascript:require('scripts/event').eventRetrievePost();


Code: [Select]

exports.eventRetrievePost = function()
{

var user = ff.getActiveUser();

var event = ff.getEventHandlerData();

event.like = ff.getObjFromUri(event.ffUrl + "/BackReferences.Like.object/(createdBy eq '"  + user.guid + "')");

event.subscription = ff.getObjFromUri(event.ffUrl + "/BackReferences.Subscription.object(createdBy eq '" + user.guid + "')");

}


I'm getting this error whenever i make most CRUD operations to the database, that aren't even related to /Event. I was trying to delete an FFUserGroup and I got three of these errors.

Quote

FatFractal.getArrayFromUri 500, {"result":null,"statusMessage":"Recursive event handler guard - count for CREATE on /Event has reached 4"}

Error 500: {"result":null,"statusMessage":"Recursive event handler guard - count for CREATE on /Event has reached 4"}
FatFractal.js:745

xmlHTTP : {"readyState":4,"timeout":0,"onloadend":null,"withCredentials":false,"status":500,"upload":{},"responseType":"","response":"{\"result\":null,\"statusMessage\":\"Recursive event handler guard - count for CREATE on /Event has reached 4\"}","statusText":"Internal Server Error","responseText":"{\"result\":null,\"statusMessage\":\"Recursive event handler guard - count for CREATE on /Event has reached 4\"}"}



The console logs are littered with entries like this

Quote

15:07:28 at org.mozilla.javascript.gen._Event_RETRIEVE_EventRetrievePost_16.call(/Event.RETRIEVE.EventRetrievePost)
15:07:28 at org.mozilla.javascript.gen._Event_RETRIEVE_EventRetrievePost_16.exec(/Event.RETRIEVE.EventRetrievePost)


I've made no attempt to make any CRUD operations with the /Events collection. I should not that I get that error for all Collections that I defined retrieve handlers for. All of the handlers are similar.

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: Retrieve Handler Issue
« Reply #1 on: January 31, 2014, 03:32:35 PM »
Hmm. Yes the object is re-retrieved (albeit from in-memory cache) and the event handler fires again. This is clearly not desired behaviour and I will rethink how the retrieve handlers work. They are intended really as a thin layer underneath the web layer but are currently implemented in the same way as the other event handlers.

In the meanwhile - I see this event handler is populating like and subscription using BackReferences.

If you create aliases for those members then you can use depthGb parameter on the front-end to retrieve those related objects in-line. See this answer: https://forum.fatfractal.com/forum/index.php?topic=32.msg140#msg140

jonnycools

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: Retrieve Handler Issue
« Reply #2 on: January 31, 2014, 03:38:41 PM »
Code: [Select]

exports.promoterRetrievePost = function()
{

var user = ff.getActiveUser();

var promoter = ff.getEventHandlerData();

promoter.like = ff.getObjFromUri("/Like/(ffRefs.url eq '" + promoter.ffUrl + "' and ffRefs.url eq '" + user.ffUrl + "')");  //ff.getObjFromUri(promoter.ffUrl + "/BackReferences.Like.object/(createdBy eq '"  + user.guid + "')");

promoter.subscription = ff.getObjFromUri("/Subscription/(ffRefs.url eq '" + promoter.ffUrl + "' and ffRefs.url eq '" + user.ffUrl + "')");

}


I'm also trying this as well.

The thing is the like and subscription is unique to the user. Getting all of them is just a waste as their could be thousands. Trust me I have trolled that post about alias. I read every post on here.

Before you rethink that. If I update a property on the event would the query use that value or the value before. Say I updated the trending value would the new value be available for query, basically allowing me to personalize the trending value for the user?

jonnycools

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: Retrieve Handler Issue
« Reply #3 on: January 31, 2014, 03:49:28 PM »
The new API you released this morning has fixed the issue. Don't know if I'm actually getting anything as there are no objects in the like or subscription collections, but that's a problem for another day.

Thanks!

Swapped to this:

Code: [Select]

exports.promoterRetrievePost = function()
{

var user = ff.getActiveUser();

var promoter = ff.getEventHandlerData();

promoter.like = ff.getObjFromUri("/Like/(ffRefs.url eq '" + promoter.ffUrl + "' and ffRefs.url eq '" + user.ffUrl + "')");

promoter.subscription = ff.getObjFromUri("/Subscription/(ffRefs.url eq '" + promoter.ffUrl + "' and ffRefs.url eq '" + user.ffUrl + "')");

}


gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: Retrieve Handler Issue
« Reply #4 on: January 31, 2014, 04:06:06 PM »
Yay! Good thinking :-)

With regards to your question
Quote
Before you rethink that. If I update a property on the event would the query use that value or the value before. Say I updated the trending value would the new value be available for query, basically allowing me to personalize the trending value for the user?
not sure I understand this ... the retrieve handlers are intended for dynamic addition (or removal) of information before sending the final response. When you make the changes to the object they are in-memory only, not persisted unless you explicitly call updateObj .. and I don't think you would want to update an object every time it is retrieved ...

jonnycools

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: Retrieve Handler Issue
« Reply #5 on: January 31, 2014, 04:13:04 PM »
Never mind, I know its not what I want (wishful thinking). Thanks for the help. I don't see any need to rethink as this works just fine. Its finally coming together

jonnycools

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: Retrieve Handler Issue
« Reply #6 on: January 31, 2014, 04:16:56 PM »
I know i'm needy, one last question.

Code: [Select]

exports.venueDeleteAsync = function()
{

var venue = ff.getEventHandlerData();

var clean = ff.getArrayFromUri(venue.ffUrl + "/account or permission or images or menu or BackReferences.Album.creator or BackReferences.Like.object or BackReferences.Review.object or BackReferences.Subscription.object or BackReferences.Event.creator or BackReferences.Employee.employer or BackReferences.EventRequest.object or BackReferences.Verification.object or BackReferences.WishListItem.object or BackReferences.Checkin.venue or BackReferences.Stream.creator or BackReferences.Activity.creator or BackReferences.Report.object or BackReferences.Photo.creator BackReferences.EventGroup.creator or BackReferences.Comment.creator");

for (var i = 0; i < clean.length; i++)
{

ff.deleteObj(clean[i]);

}

}


Could I do this async after the object has been deleted? I.E would the venue's ffUrl still be valid to find references or would I need to use POST or PRE? I'm scarred to use pre as I feel it would be excited before validation.

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: Retrieve Handler Issue
« Reply #7 on: January 31, 2014, 04:27:39 PM »
You have to do this kind of stuff in a PRE handler; once the object is gone, it's gone

When you say you're scared it would be executed before validation - if you're worried about security, rest assured, the security check for creates / updates / deletes is always done before any event handler fires

 

Copyright © FatFractal customer forums