Issues

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

You can use cache to store metadata

http://framework.zend.com/manual/en/…

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.

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.

The patch works well. I personally prefer the first approach, using a getter would communicate more clearly that the metadata is not automatically available

You are right, Eran. It's more clean when you use getter method. I made new patch in next few days.

modified info() method

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.

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.

Changing issues in preparation for the 1.7.0 release.