On Martes, 21 de Julio de 2009 23:22:37 mvargo escribió:
> OK, I think I can see what is happening.  I'm trying to display 10
> rows of reader_device records.  The log is shown below.  The thing to
> look at is the line that says "Delivery Load".  That is a select of
> the actual records associated with these particular 10
> reader_devices.  In this particular instance, that is over 17,000
> records.  It's not selecting count(*) or anything, but actually
> retrieving all 17000 records even though it's not going to display
> them.  I imagine it must be sorting them out in ruby.  It seems to me
> that it should be doing 10 calls to select count(*) from [delivery]
> where reader_device = 2375 etc.

This queries load whole associations which are shown in list. It's due to 
eager loading. You can disable eager loading in an association setting to nil 
the includes attribute:
config.columns[:delivery_loads].includes = nil

> Subscriber Load (0.8ms)   SELECT * FROM [subscriber] WHERE
> ([subscriber].[id] IN
> (2376,2377,2378,2380,2379,2381,2382,2383,2384,2375))
>   Delivery Load (5.3ms)   SELECT [delivery].* FROM [delivery] WHERE
> ([delivery].reader_device_id IN
> (2375,2376,2377,2378,2379,2380,2381,2382,2383,2384))

Anyway, disabling eager loading doesn't fix it, because there are some methods 
which load whole association to get some information:

* length method is was being used in the association in order to get a count, 
but length seems to load all records and use the array length method. I have 
changed it to size, which uses a select count(*) query when association is not 
loaded (so with eager loading it doesn't throws a query)

* Also, to get firsts associated records it was using the "first" method, but 
that method loads all associated records when you use it with a integer (to 
get more than first record)

* And there were some locations where whole association was loaded too.

It should be fixed now, please try it

>
> This seems like a pretty big flaw.  Somebody must have a workaround
> for this.
>
> Mike Vargo
>
> Processing ReaderDevicesController#index (for 127.0.0.1 at 2009-07-21
> 14:15:25) [GET]
>   User Load (0.7ms)   SELECT * FROM [user] WHERE ([user].[id] = 3)
>   SQL (3.3ms)   SELECT count(DISTINCT [reader_device].id) AS count_all
> FROM [reader_device] LEFT OUTER JOIN [build_target] ON
> [build_target].id = [reader_device].build_target_id LEFT OUTER JOIN
> [subscriber] ON [subscriber].id = [reader_device].subscriber_id LEFT
> OUTER JOIN [delivery] ON delivery.reader_device_id = reader_device.id
>   SQL (0.6ms)   SELECT count(*) as TotalRows from (SELECT TOP
> 1000000000 [reader_device].* FROM [reader_device] ORDER BY
> reader_device.[id] ASC) tally
>   ReaderDevice Load (1.1ms)   SELECT * FROM (SELECT TOP 10 * FROM
> (SELECT TOP 50 [reader_device].* FROM [reader_device] ORDER BY
> reader_device.[id] ASC) AS tmp1 ORDER BY id DESC) AS tmp2 ORDER BY id
> ASC
>   BuildTarget Load (0.7ms)   SELECT * FROM [build_target] WHERE
> ([build_target].[id] = 4)
>   Subscriber Load (0.8ms)   SELECT * FROM [subscriber] WHERE
> ([subscriber].[id] IN
> (2376,2377,2378,2380,2379,2381,2382,2383,2384,2375))
>   Delivery Load (5.3ms)   SELECT [delivery].* FROM [delivery] WHERE
> ([delivery].reader_device_id IN
> (2375,2376,2377,2378,2379,2380,2381,2382,2383,2384))
> Rendering template within layouts/admin_portal
> Rendering list
> Rendered _list_header (10.7ms)
> Rendered _list_column_headings (22.5ms)
> Rendered _messages (2.1ms)
> Rendered _list_actions (15.6ms)
> Rendered _list_record (74.5ms)
> Rendered _list_actions (2.3ms)
> Rendered _list_record (11.7ms)
> Rendered _list_actions (2.1ms)
> Rendered _list_record (10.9ms)
> Rendered _list_actions (2.0ms)
> Rendered _list_record (10.8ms)
> Rendered _list_actions (1.9ms)
> Rendered _list_record (10.6ms)
> Rendered _list_actions (2.0ms)
> Rendered _list_record (10.6ms)
> Rendered _list_actions (1.1ms)
> Rendered _list_record (6.1ms)
> Rendered _list_actions (1.1ms)
> Rendered _list_record (5.6ms)
> Rendered _list_actions (1.0ms)
> Rendered _list_record (5.5ms)
> Rendered _list_actions (1.0ms)
> Rendered _list_record (5.5ms)
> Rendered _list_pagination_links (10.5ms)
> Rendered _list (212.0ms)
> Completed in 22166ms (View: 494, DB: 24) | 200 OK [http://localhost/
> reader_devices]
>
>
> 
-- 
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [email protected]


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to