Ticket #1636 (closed defect: fixed)

Opened 8 months ago

Last modified 7 months ago

Result caching for queries with joins is not fully working

Reported by: esycat Owned by: romanb
Priority: major Milestone: 1.0.6
Component: Caching Version: 1.0.3
Severity: Keywords:
Cc: Has Test: yes
Status: Pending Core Response Has Patch: yes

Description (last modified by vladb) (diff)

When using result cache for queries with joins, data of joined models is not being cached and/or reconstructed back from the cache properly, which leads to new unexpected individual queries for lazy loading.

 Discussion.

PHP 5.2.6 with Suhosin-Patch 0.9.6.2 (cli)
Doctrine 1.0.3

Attachments

1636TestCase.php (5.3 KB) - added by esycat 8 months ago.
Test Case.
1636patch1.0 (367 bytes) - added by andyman3000 7 months ago.
fixes #1636

Change History

Changed 8 months ago by esycat

  • has_test set

Changed 8 months ago by esycat

  • description modified (diff)

As I have investigated, data of joined models is not cached at all. The reason is that Doctrine_Record::serialize() removes relations before serialization:

unset($vars['_references']);

When I commented out this line, my test case passes successfully, but I'm not sure would it be OK to just delete this line?

Changed 8 months ago by esycat

  • milestone changed from Unknown to 1.0.4

Changed 8 months ago by esycat

Chapter "7.1.12 Serializing" of User Manual states: Records can be serialized, but remember: Doctrine cleans all relations, before doing this.

So, removing references is documented behavior, but it contradict examples of result cache usage.

Changed 8 months ago by esycat

Test Case.

Changed 7 months ago by vladb

  • description modified (diff)

May I stress the magnitude of this problem; join queries are more often than not more resource consuming that regular ones. Not being able to cache them (and moreso, creating overhead IF YOU DO) simply invalidates the caching mechanism itself and makes Doctrine unsuitable for large scale projects -- which is, exactly where using Doctrine makes a lot of sense.

I apologize for stating the obvious, obviously I've just bumped into the problem. I'll look through the code and see if I can come up with a solution, although my experience with Doctrine internals is pretty much non-existent.

Changed 7 months ago by romanb

Just to be clear, this is a known limitation. The result cache works fine with a) single objects, b) a flat list of objects, c) an array graph (HYDRATE_ARRAY), d) Other scalar hydration modes.

The only thing that does *not* work is caching object graphs because the associations are not reconstructed. We're open to proposed solutions but they need to be tested properly.

Automatic lazy-loading just makes this limitation worse when it is encountered, this is a negative effect of lazy-loading and the reason why lazy-loading will not be enabled by default in the future.

Changed 7 months ago by andyman3000

fixes #1636

Changed 7 months ago by andyman3000

Patch created.

Changed 7 months ago by andyman3000

from what I can tell,removing the line unset($vars_references?); from the seralization method in the Record class removes the issue and doesn't break anything. However I am a little concerned, about memory consumption. Will all the recursions be removed? I have been using it in dev environment too for two days and its looking ok so far.

Changed 7 months ago by andyman3000

  • has_patch set

Changed 7 months ago by jwage

  • status changed from new to closed
  • resolution set to fixed

(In [5301]) [1.0, 1.1] Fixing issue with resultset cache and joined records (closes #1636)

Changed 7 months ago by jwage

(In [5316]) [1.0, 1.1] Fixes regression in resultset cache (closes #1768) and (addresses #1636 again)

Changed 7 months ago by jwage

  • milestone changed from 1.0.5 to 1.0.6
Note: See TracTickets for help on using tickets.