Forum: Ruby on Rails What am I missing?? Activerecord & Sessions!!

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Tyler Keating (Guest)
on 2006-03-02 17:47
Can someone please explain why every time that I call an action in my
controller, every model that is stored in the session needs to be
interpreted by a database query?  If I have four models stored in the
session, I end up with five long "SELECT a.attname,
format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull FROM
pg_attribute a LEFT JOIN pg_attrdef d....." queries when *ANY* action is
called.  I've tried adding the models in my ApplicationController, but
to no avail.

It is extremely annoying to sort through the console messages with these
repeating queries.  Is this supposed to be happening????  Why do normal
ActiveRecord objects not need this query when they are used??

It started when I moved to PostgreSQL.

Thanks for any insight,
Tyler
Tyler Keating (Guest)
on 2006-03-03 17:12
Well, I figured out that the metadata queries are normal behaviour,
because in development mode I'm not caching classes (ie.
config.cache_classes = false).  To not see the queries, I simply need to
cache the classes so that the metadata is only queried once and then
saved.

I don't want to have to keep restarting the server repeatedly in between
each change, but the metadata queries are becoming unbearable.  Consider
loading a list of images from the database using an action.  With 4
models in the session plus the image model, I end up with 35 lines of
log garbage for each image retrieved.  Multiply that by 10 images and
it's a total mess.

My question again "Is there a way to hide the metadata queries and still
not cache classes???"  I'm considering going back to MySQL just because
the metadata queries are at least compact "SHOW FIELDS FROM xxxx;"

Tyler
Josh S. (Guest)
on 2006-03-03 18:11
Is it important to have the actual model objects in the session? I find
it's usually sufficient to keep the model id in the session, and avoids
just this sort of problem.

--josh
http://blog.hasmanythrough.com

Tyler Keating wrote:
> Well, I figured out that the metadata queries are normal behaviour,
> because in development mode I'm not caching classes (ie.
> config.cache_classes = false).  To not see the queries, I simply need to
> cache the classes so that the metadata is only queried once and then
> saved.
>
> I don't want to have to keep restarting the server repeatedly in between
> each change, but the metadata queries are becoming unbearable.  Consider
> loading a list of images from the database using an action.  With 4
> models in the session plus the image model, I end up with 35 lines of
> log garbage for each image retrieved.  Multiply that by 10 images and
> it's a total mess.
>
> My question again "Is there a way to hide the metadata queries and still
> not cache classes???"  I'm considering going back to MySQL just because
> the metadata queries are at least compact "SHOW FIELDS FROM xxxx;"
>
> Tyler
Tyler Keating (Guest)
on 2006-03-03 19:03
I have gone through my session use and reduced the number of model
objects.  I would say at the expense of more database queries, but I
realize that I'll be storing the session objects in the database at some
point down the road anyways.  It's an improvement for sure, but still
doesn't solve displaying several database images on a page, because each
action must query the metadata for the Image class.  Just trying to
display ten images creates 60 extra lines in the log everytime I reload
a page.

I guess I'll have to implement image caching sooner than later...
Thanks,
Tyler

Josh S. wrote:
> Is it important to have the actual model objects in the session? I find
> it's usually sufficient to keep the model id in the session, and avoids
> just this sort of problem.
>
> --josh
> http://blog.hasmanythrough.com
>
> Tyler Keating wrote:
>> Well, I figured out that the metadata queries are normal behaviour,
>> because in development mode I'm not caching classes (ie.
>> config.cache_classes = false).  To not see the queries, I simply need to
>> cache the classes so that the metadata is only queried once and then
>> saved.
>>
>> I don't want to have to keep restarting the server repeatedly in between
>> each change, but the metadata queries are becoming unbearable.  Consider
>> loading a list of images from the database using an action.  With 4
>> models in the session plus the image model, I end up with 35 lines of
>> log garbage for each image retrieved.  Multiply that by 10 images and
>> it's a total mess.
>>
>> My question again "Is there a way to hide the metadata queries and still
>> not cache classes???"  I'm considering going back to MySQL just because
>> the metadata queries are at least compact "SHOW FIELDS FROM xxxx;"
>>
>> Tyler
This topic is locked and can not be replied to.