ZF-2510: Lazy loading table metadata
Description
When instanced, a Zend_Db_Table object automatically attempts to retrieve table meta-data. This is counterproductive for several reasons - 1. Performance - An extra database call, even if the metadata is not used. 2. Complicated unit test writting process - as testing Zend_Db_Table extending classes requires a live db connection to allow the Zend_Db_Table object to retrieve its metadata, even if not used.
A better solution would be to lazy load the metadata when it is requested (for example, when the info() method is called).
Comments
Posted by Kamil Nowakowski (kamiln) on 2008-01-28T07:05:46.000+0000
You can use cache to store metadata
http://framework.zend.com/manual/en/…
Posted by Eran Galperin (erangalp) on 2008-01-28T10:08:48.000+0000
I am using cache to store the metadata as a workaround for this issue. However, it is still prefered that it won't have to retrieve the metadata (even from the cache) if not needed.
Why should the metadata be retrieved if not used? The cache is just a workaround to a design flaw.
Posted by Ondrej Ivanic (ondrej) on 2008-03-01T19:38:15.000+0000
Patch for this issue against r8510. Comments are welcome.
I played with two versions: 1) getter for _metadata and _cols properties 2) call _setupMetadata method when _metadata or _cols are need.
Attached patch implements second version.
Posted by Eran Galperin (erangalp) on 2008-03-01T21:09:14.000+0000
The patch works well. I personally prefer the first approach, using a getter would communicate more clearly that the metadata is not automatically available
Posted by Ondrej Ivanic (ondrej) on 2008-03-02T03:23:59.000+0000
You are right, Eran. It's more clean when you use getter method. I made new patch in next few days.
Posted by Ondrej Ivanic (ondrej) on 2008-03-16T12:44:21.000+0000
modified info() method
Posted by Matthew Weier O'Phinney (matthew) on 2008-11-04T10:36:39.000+0000
The second patch also accomplishes another objective: allowing hard coding of the metadata and cols attributes. This would give an additional performance optimization for the truly adventurous.
Posted by Matthew Weier O'Phinney (matthew) on 2008-11-04T14:48:23.000+0000
Patch (with modifications) applied in r12290, with test modifications (to account for lazy loading) and addition of flag for overriding local metadata caching. Documentation also provided.
Posted by Wil Sinclair (wil) on 2008-11-13T14:10:29.000+0000
Changing issues in preparation for the 1.7.0 release.