Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8800 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

[PATCH] has_many :through collections.size shouldn't load target if it's not loaded already

Reported by: lifofifo Assigned to: bitsweat
Priority: normal Milestone: 1.x
Component: ActiveRecord Version: edge
Severity: normal Keywords: hmt
Cc:

Description

For has_many :through, collections.size loads target even if it wasn't loaded before.

So instead of count(*) query, collections.size triggers SELECT * query, which is slower than simple count query.

has_many collections.size use count(*) query if the target is not loaded. HMT should do the same.

The patch fixes the issues and implement relevant test.

Thanks.

Attachments

hmt_collection_size_shouldnt_load_target.patch (2.0 kB) - added by lifofifo on 06/29/07 00:32:12.
has_many :through collections.size shouldn't load target
hmt_collection_size_shouldnt_load_target.2.patch (1.7 kB) - added by kamal on 06/29/07 01:39:00.
refactored to use count method in #8801
hmt_collection_size_shouldnt_load_target.2.2.patch (1.6 kB) - added by lifofifo on 07/20/07 00:30:49.
Updated against latest edge

Change History

06/29/07 00:32:12 changed by lifofifo

  • attachment hmt_collection_size_shouldnt_load_target.patch added.

has_many :through collections.size shouldn't load target

06/29/07 00:45:09 changed by lifofifo

  • keywords set to hmt.

06/29/07 01:39:00 changed by kamal

  • attachment hmt_collection_size_shouldnt_load_target.2.patch added.

refactored to use count method in #8801

06/29/07 01:39:45 changed by kamal

Refactored to use count method in #8801, so I guess this patch depends on #8801

07/01/07 23:51:24 changed by lifofifo

  • owner changed from core to bitsweat.

07/20/07 00:30:49 changed by lifofifo

  • attachment hmt_collection_size_shouldnt_load_target.2.2.patch added.

Updated against latest edge

07/25/07 03:09:25 changed by rick

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

(In [7237]) Ensure that has_many :through associations use a count query instead of loading the target when #size is called. Closes #8800 [lifo]