[coldbox-4.1.0][cborm-] Disable event handling for specific entities?

Is it possible to disable or bypass the event handler for specific entities that don’t need to be injected with anything by Wirebox?

I have an entity that’s frequently being loaded in bulk (1000+) and it’s very slow with eventHandling turned on - it takes about 6-7 seconds to load 2000 objects, each and every time. With eventHandling turned off it only takes less than 2.5 seconds on the first load, but it quickly reduces to less than 100ms on subsequent loads.


In your handler, just add that method in to this configuration in your handler:

this.aroundhandler_except = "myAction"

That will exempt that method from the aroundHandler() actions: http://coldbox.ortusbooks.com/content/event_handlers/handler_interception_methods.html . If you have preHandler and postHandler methods you can also use this.prehandler_except and this.posthandler_except as well.

If you are running in to this in development, you may want to trying the framework in production mode before you exempt the method, though. There will be a significant increase in performance once you let Coldbox “go live”.



Thanks Jon for your reply, but as far as I can tell what you’ve suggested is for normal CB event handlers. What I’m looking for is exemption for ORM event handling for specific entities.

Sorry, Nick. I missed the [cborm…] in the subject line. How are you loading the objects? There’s no way, that I know of, to turn off event handling temporarily, other than turning it off at the application level. There may be ways you can speed up the loading of the objects, themselves, though, specifically in tweaking the lazy loading settings and using batchsize attributes on one-to-many and many-to-many relationships.

If you can post a code sample of how you’re loading, it might help to suggest ways to improve the performance with event handling on.

One other note: one way to bypass event handling somewhat is to use a criteria query in lieu of loading the objects through their ORM mappings. When dealing with large recordsets, criteria queries are much, much faster and allow more optimization.


var criteria = getModel("Friends").newCriteria();
var friends = criteria.list();

is exponentionally faster, the larger the relationship set, than:

var friends = getModel("Person").get(id).getFriends();



If you are dealing with thousands of records, I would recommend using a query instead of an array of objects. IF you must have objects, can you pull some stack traces and see which code is taking the longest?



ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thanks Jon and Brad for your suggestions. I’ve decided to “unwire” my entities and disable eventHandling completely for now, until I have time to figure out a better solution.