By default, all associated records of all records which are going to be shown 
in the page are loaded, to reduce the number of queries. For little 
associations is faster to eager loading the associations. When you have big 
associations, to avoid loading many records you have to disable eager loading, 
look at includes in api: column: 
http://wiki.github.com/activescaffold/active_scaffold/api-column

config.columns[:association_name].includes = nil

Disabling it you will get a query to get the real associated records to show 
for each record, limiting to associated_limit + 1.
You will get multiple duplicated select count queries, there are 3 ways to get 
the count for an association in rails:
* length, it loads all records (if they are not cached) and get the array 
length
* count, it makes a select count query
* size, if records are cached it gets the array length, in other case it makes 
a select count query. (AS uses this)

As rails doesn't cache the count for an association, and when eager loading is 
disabled, each time we need the count a new query is made (although mysql 
should have it cached). Also, to check permissions you will get a query to get 
the first record.

I have improved it, caching the first query with the rails mechanism, query 
loads only associated_limit (without +1, it loads at least 1 although you set 
associated_limit to zero), and cached sql queries should be avoided now. Also 
getting first record to check permissions shouldn't do a sql query.

On Jueves, 24 de Septiembre de 2009 20:10:45 alexp escribió:
> Apolgies in advance if this is rails thing as its driving my round the
> bend knowing how much extra cpu is being burnt
>
> whilst debugging my last issue
>
> config.list.per_page=1 to test out, later change this to 20
> added <%=debug record%> to _list_actions and added it as an override
> to test out...shock horror on what is going on.
>
> I cant understand this redundancy - to load a row and display only
> columns x,y of model A, x,y of model B etc the entire row's records
> are loaded IN FULL instead of what is actually needed - the data to be
> displayed.
>
> I have in a list view
> Manager, Team, Player
>
> A manager (10 fields) has 20 teams, each team(20 fields) has 200
> players(30 fields) = 4000 total records, each player has lots of
> fields and lots of text
>
> try loading a list of managers with associated teams (limited to
> display 5), list the players(first 5 belonging to manager) you get the
> full list of objects loaded - given that I have limited
> config.columns[:players].associated_limit = 1, it still does a FULL
> load of every player record - I still have to reed 4000 player objects
> in full, (each player has 30 fields - tons of text/strings etc).  This
> is just mind blowing that
> columns[:players].associated_limit = 1, doesnt limit any thing, the db
> is still read for every record, instead of doing a count (i.e. 1) and
> reading the record that needs to be displayed (the first).  The rest
> are not needed
>
> Now list 20 managers per page, thats 20000 db objects read for a
> single page....whilst only the manager name, team name + count, player
> name + count is displayed + EDIT, SHOW.
>
> Then for each security action (CRUD) the process is done again - the
> full list of objects are loaded with all associated records read in
> full...ouch ouch ouch
>
> I've tested and from what I can see the actual calls to mysql, in the
> above example with all options EDIT, SHOW, DELETE a total of 60000
> objects were loaded and over 100000 calls to the db....seriously a
> joke. FOR 1 PAGE!!!
>
> It makes my skin crawl watching the db go mad like this - I dont like
> wasting my poor little CPU on my laptop but this is killing my
> machine!!
>
> I know its work in progress but this goes against everything I have
> ever learned, why is so much being loaded when it isnt being used,
> displayed to the user!
>
> Somebody please help me reduce this down to normality!!
>
> 
-- 
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