Hello, I''m following the tutorial http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html to have an idea of what Rails is. It looks very cool and I like it, but: 1) I can''t find a "deep guide". The tutorial is good, the API doc are also very good. But does a real "Manual" exist? 2) Is there any way to cache colums types when using Active Record? Every time I access an object a query to the DB is issued to get all the columns (with their types) from the db (query shown at the end of the post). This is ok for development, but I don''t think is suitable on a production system. Is there a way to avoid it, using a cache (that could be invalidated somehow)? thanks in advance for your replies <db queries always issued> LOG: statement: SELECT column_name, column_default, character_maximum_length, data_type FROM information_schema.columns WHERE table_catalog = ''cookbook'' AND table_schema = ''public'' AND table_name = ''recipes''; LOG: statement: SELECT CASE WHEN $2.typtype = ''d'' THEN $2.typbasetype ELSE $1.atttypid END CONTEXT: SQL function "_pg_truetypid" during inlining LOG: statement: SELECT CASE WHEN $2.typtype = ''d'' THEN $2.typtypmod ELSE $1.atttypmod END CONTEXT: SQL function "_pg_truetypmod" during inlining LOG: statement: SELECT CASE WHEN $2 = -1 /* default typmod */ THEN null WHEN $1 IN (1042, 1043) /* char, varchar */ THEN $2 - 4 WHEN $1 IN (1560, 1562) /* bit, varbit */ THEN $2 ELSE null END CONTEXT: SQL function "_pg_char_max_length" during inlining LOG: statement: SELECT CASE WHEN $2.typtype = ''d'' THEN $2.typbasetype ELSE $1.atttypid END CONTEXT: SQL function "_pg_truetypid" during startup LOG: statement: SELECT CASE WHEN $2.typtype = ''d'' THEN $2.typtypmod ELSE $1.atttypmod END CONTEXT: SQL function "_pg_truetypmod" during startup LOG: statement: SELECT CASE WHEN $2 = -1 /* default typmod */ THEN null WHEN $1 IN (1042, 1043) /* char, varchar */ THEN $2 - 4 WHEN $1 IN (1560, 1562) /* bit, varbit */ THEN $2 ELSE null END CONTEXT: SQL function "_pg_char_max_length" during startup </db queries always issued>
> 2) Is there any way to cache colums types when using Active Record?In production environment, the models are cached.> Every time I access an object a query to the DB is issued to get all the > columns (with their types) from the db (query shown at the end of the > post). This is ok for development, but I don''t think is suitable on a > production system. Is there a way to avoid it, using a cache (that could > be invalidated somehow)?Not every time you access the objects, but once per request. Tomas
Tomas Jogin wrote:>>2) Is there any way to cache colums types when using Active Record? > > In production environment, the models are cached.Cool! But that is what I was talking about... how could I know it ;) ? Could you point me to some docs? And: in a production environment, can I invalidate the cache (in case I change my db schema)? Thank you!
> > In production environment, the models are cached. > > Cool! But that is what I was talking about... how could I know it ;) ? > Could you point me to some docs?Sorry, don''t know actually. Either I don''t know where the docs say so, or the docs has some gaps.> And: in a production environment, can I invalidate the cache (in case I > change my db schema)?Just restart the web server or kill the FastCGI-processes, the model cache is stored in memory. AFAIK, since a few versions back, the model cache is automagically invalidated if the models are changed. Anyone, go ahead and correct me if I''m wrong here. Regards, Tomas
Actually I found that ActiveRecordBase#attributes_from_column_definition goes though connection adapter (re)executing query instead of using column hash from Base#columns. Is this by accident or purpose? I submitted a patch to this but unfortunately it is bundled with other unfinished changes from #608. Cheers, Zsombor On 4/18/05, Tomas Jogin <tomasj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > In production environment, the models are cached. > > > > Cool! But that is what I was talking about... how could I know it ;) ? > > Could you point me to some docs? > > Sorry, don''t know actually. Either I don''t know where the docs say so, > or the docs has some gaps. > > > And: in a production environment, can I invalidate the cache (in case I > > change my db schema)? > > Just restart the web server or kill the FastCGI-processes, the model > cache is stored in memory. AFAIK, since a few versions back, the model > cache is automagically invalidated if the models are changed. Anyone, > go ahead and correct me if I''m wrong here. > > Regards, > Tomas > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- http://deezsombor.blogspot.com
Dee Zsombor wrote:>Actually I found that >ActiveRecordBase#attributes_from_column_definition goes though >connection adapter (re)executing query instead of using column hash >from Base#columns. Is this by accident or purpose? > >I submitted a patch to this but unfortunately it is bundled with other >unfinished changes from #608. >A have also suggested this, see http://dev.rubyonrails.org/ticket/912 -- stefan
See http://rails.rubyonrails.com/classes/ActionController/Caching.html for caching documentation Dee Zsombor wrote:>Actually I found that >ActiveRecordBase#attributes_from_column_definition goes though >connection adapter (re)executing query instead of using column hash >from Base#columns. Is this by accident or purpose? > >I submitted a patch to this but unfortunately it is bundled with other >unfinished changes from #608. > >Cheers, >Zsombor > >On 4/18/05, Tomas Jogin <tomasj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >>>>In production environment, the models are cached. >>>> >>>> >>>Cool! But that is what I was talking about... how could I know it ;) ? >>>Could you point me to some docs? >>> >>> >>Sorry, don''t know actually. Either I don''t know where the docs say so, >>or the docs has some gaps. >> >> >> >>>And: in a production environment, can I invalidate the cache (in case I >>>change my db schema)? >>> >>> >>Just restart the web server or kill the FastCGI-processes, the model >>cache is stored in memory. AFAIK, since a few versions back, the model >>cache is automagically invalidated if the models are changed. Anyone, >>go ahead and correct me if I''m wrong here. >> >>Regards, >>Tomas >>_______________________________________________ >>Rails mailing list >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> > > > >
That''s a completely different kind of caching. On 4/18/05, Dominic Sisneros <dsisnero-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote:> See http://rails.rubyonrails.com/classes/ActionController/Caching.html > for caching documentation > > > Dee Zsombor wrote: > > >Actually I found that > >ActiveRecordBase#attributes_from_column_definition goes though > >connection adapter (re)executing query instead of using column hash > >from Base#columns. Is this by accident or purpose? > > > >I submitted a patch to this but unfortunately it is bundled with other > >unfinished changes from #608. > > > >Cheers, > >Zsombor > > > >On 4/18/05, Tomas Jogin <tomasj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > >>>>In production environment, the models are cached. > >>>> > >>>> > >>>Cool! But that is what I was talking about... how could I know it ;) ? > >>>Could you point me to some docs? > >>> > >>> > >>Sorry, don''t know actually. Either I don''t know where the docs say so, > >>or the docs has some gaps. > >> > >> > >> > >>>And: in a production environment, can I invalidate the cache (in case I > >>>change my db schema)? > >>> > >>> > >>Just restart the web server or kill the FastCGI-processes, the model > >>cache is stored in memory. AFAIK, since a few versions back, the model > >>cache is automagically invalidated if the models are changed. Anyone, > >>go ahead and correct me if I''m wrong here. > >> > >>Regards, > >>Tomas > >>_______________________________________________ > >>Rails mailing list > >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >>http://lists.rubyonrails.org/mailman/listinfo/rails > >> > >> > >> > > > > > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Monday, April 18, 2005, 7:53:06 PM, Leonardo wrote:>>> 2) Is there any way to cache colums types when using Active Record?>> In production environment, the models are cached.> Cool! But that is what I was talking about... how could I know it ;) ? > Could you point me to some docs?In response to this, I created http://wiki.rubyonrails.com/rails/show/DevTestProductionManual but I know little about the topic. Those who know, please contribute. And write more "manuals" in response to frequently asked good questions. Gavin