ooor icon indicating copy to clipboard operation
ooor copied to clipboard

should use lazy proxy on m2o and x2m associations

Open rvalyi opened this issue 11 years ago • 3 comments
trafficstars

m2o product1.categ_id should 1st load ProductCategory proxy with just the name (default to the rec_name read) and the id. And it should hit the server and request all other lazy fields only if other fields are asked.

x2m for x2m, a CollectionProxy should mimic only a collections with the id attribute and should lazily hit OpenERP to retrieve all other fast fields of all the collection if any other field is asked.

rvalyi avatar Apr 23 '14 06:04 rvalyi

done for m2o with the lazy property

rvalyi avatar Apr 28 '14 05:04 rvalyi

for o2m associations, an idea could be that in relation.rb, in method_missing, when we have the method, of an Array (:each), with a Proc passed, then we could may be call to_a with a special option so that when it will do the find upon the specified ids scope, it just build the proxies with just their id and the lazy flag on without hitting OpenERP yet.

Then when the first accessor will be called upon the first item, we should be able to figure out that this lazy proxy belongs to some owner object with a collection association. So we should reload all the proxies of the collection all together in a single call to OpenERP.

Additionally, this gives us the opportunity to inject the requested field along with the "fast_fields" to eager load them in the single request.

That would be interesting to know if we could collect all the accessors called upon the collection items within the block and request them altogether. It's worth looking f other ORM are able to introspect somewhat the iteration block or able to collect all the requests fields. For instance Datamapper says it fixes the N+1 problem in "Strategic Eager Loading" http://datamapper.org/why.html are they just eager loading a list of fields or are them doing something smarter?

rvalyi avatar Apr 28 '14 06:04 rvalyi

actually, it's probably where CollectionProxy should start kicking'in when we create one for the x2m associations

rvalyi avatar Apr 28 '14 07:04 rvalyi