Matthijs Langenberg
2008-Oct-31 12:36 UTC
Resetting the template or class cache in Rails 2.2.0
While testing the Rails 2.2.0 release I soon knew I had a problem: I''m relying on the fact that an ERB template is recompiled if the modification time of the file has been updated. I work on a multisite Rails app, which uses ''request.host'' to do a Site.find_by_domain and uses a before filter to call ''prepend_view_path("#{RAILS_ROOT}/themes/#{@site.domain}/templates"). It''s also possible to upload a new theme for a specific site via an admin backend. It''s comparable to Shopify, but instead of using Liquid it relies on Rails'' templating mechanism. The line of code that made this work is located here: http://github.com/rails/rails/tree/v2.1.2/actionpack/lib/action_view/template_handlers/compilable.rb#L70, but in rails-2.2.0 thing have been rewritten and the check is unfortunately gone: http://github.com/rails/rails/tree/v2.2.0/actionpack/lib/action_view/renderable.rb#L90. Currently this means that I need to run this app in production with ''config.cache_classes = false'' in order to upgrade to Rails 2.2.0, which reloads all application code on every requests. That''s going to be slow. Another solution is restarting the whole app after changing the theme for a single site. Is there a way for me to reset the template cache manually after a theme has been updated? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Oct-31 13:01 UTC
Re: Resetting the template or class cache in Rails 2.2.0
On 31 Oct 2008, at 12:36, Matthijs Langenberg wrote:> > While testing the Rails 2.2.0 release I soon knew I had a problem: I''m > relying on the fact that an ERB template is recompiled if the > modification time of the file has been updated. > > I work on a multisite Rails app, which uses ''request.host'' to do a > Site.find_by_domain and uses a before filter to call > ''prepend_view_path("#{RAILS_ROOT}/themes/#{@site.domain}/templates"). > It''s also possible to upload a new theme for a specific site via an > admin backend. > It''s comparable to Shopify, but instead of using Liquid it relies on > Rails'' templating mechanism. > > The line of code that made this work is located here: > http://github.com/rails/rails/tree/v2.1.2/actionpack/lib/action_view/template_handlers/compilable.rb#L70 > , > but in rails-2.2.0 thing have been rewritten and the check is > unfortunately gone: http://github.com/rails/rails/tree/v2.2.0/actionpack/lib/action_view/renderable.rb#L90 > . > > Currently this means that I need to run this app in production with > ''config.cache_classes = false'' in order to upgrade to Rails 2.2.0, > which reloads all application code on every requests. That''s going to > be slow. Another solution is restarting the whole app after changing > the theme for a single site. > > Is there a way for me to reset the template cache manually after a > theme has been updated?You could just override that recompile? method Fred> > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matthijs Langenberg
2008-Oct-31 13:06 UTC
Re: Resetting the template or class cache in Rails 2.2.0
Fred, I think I could write a patch that will take the file modification date into consideration, but I''m also eager to know, why the check has actually been removed. - Matthijs On Oct 31, 2:01 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 31 Oct 2008, at 12:36, Matthijs Langenberg wrote: > > > > > > > While testing the Rails 2.2.0 release I soon knew I had a problem: I''m > > relying on the fact that an ERB template is recompiled if the > > modification time of the file has been updated. > > > I work on a multisite Rails app, which uses ''request.host'' to do a > > Site.find_by_domain and uses a before filter to call > > ''prepend_view_path("#{RAILS_ROOT}/themes...-iQa0C6aySxDUF6G2QusZNg@public.gmane.org}/templates"). > > It''s also possible to upload a new theme for a specific site via an > > admin backend. > > It''s comparable to Shopify, but instead of using Liquid it relies on > > Rails'' templating mechanism. > > > The line of code that made this work is located here: > >http://github.com/rails/rails/tree/v2.1.2/actionpack/lib/action_view/... > > , > > but in rails-2.2.0 thing have been rewritten and the check is > > unfortunately gone:http://github.com/rails/rails/tree/v2.2.0/actionpack/lib/action_view/... > > . > > > Currently this means that I need to run this app in production with > > ''config.cache_classes = false'' in order to upgrade to Rails 2.2.0, > > which reloads all application code on every requests. That''s going to > > be slow. Another solution is restarting the whole app after changing > > the theme for a single site. > > > Is there a way for me to reset the template cache manually after a > > theme has been updated? > > You could just override that recompile? method > > Fred > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Maurício Linhares
2008-Oct-31 13:08 UTC
Re: Resetting the template or class cache in Rails 2.2.0
My bet is that it isn''t thread-safe. Two actions may check at the same time, both will get a "true" and both will try to update the cache. - Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) João Pessoa, PB, +55 83 8867-7208 On Fri, Oct 31, 2008 at 10:06 AM, Matthijs Langenberg <mlangenberg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Fred, > > I think I could write a patch that will take the file modification > date into consideration, but I''m also eager to know, why the check has > actually been removed. > > - Matthijs--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matthijs Langenberg
2008-Oct-31 16:35 UTC
Re: Resetting the template or class cache in Rails 2.2.0
I don''t understand. If checking if a template has already been compiled is thread-safe, checking the modification date should also be thread-safe. If thread safety is the issue here, would there be an option for me to reset all compiled templates at once? On Oct 31, 2:08 pm, "Maurício Linhares" <mauricio.linha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> My bet is that it isn''t thread-safe. Two actions may check at the same > time, both will get a "true" and both will try to update the cache. > > - > Maurício Linhareshttp://alinhavado.wordpress.com/(pt-br) |http://blog.codevader.com/(en) > João Pessoa, PB, +55 83 8867-7208 > > On Fri, Oct 31, 2008 at 10:06 AM, Matthijs Langenberg > > <mlangenb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Fred, > > > I think I could write a patch that will take the file modification > > date into consideration, but I''m also eager to know, why the check has > > actually been removed. > > > - Matthijs--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Maurício Linhares
2008-Oct-31 16:39 UTC
Re: Resetting the template or class cache in Rails 2.2.0
Maybe you could remove the whole compliled templates folder. - Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) João Pessoa, PB, +55 83 8867-7208 On Fri, Oct 31, 2008 at 1:35 PM, Matthijs Langenberg <mlangenberg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I don''t understand. If checking if a template has already been > compiled is thread-safe, checking the modification date should also be > thread-safe. > > If thread safety is the issue here, would there be an option for me to > reset all compiled templates at once? > > On Oct 31, 2:08 pm, "Maurício Linhares" <mauricio.linha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> My bet is that it isn''t thread-safe. Two actions may check at the same >> time, both will get a "true" and both will try to update the cache. >> >> - >> Maurício Linhareshttp://alinhavado.wordpress.com/(pt-br) |http://blog.codevader.com/(en) >> João Pessoa, PB, +55 83 8867-7208 >> >> On Fri, Oct 31, 2008 at 10:06 AM, Matthijs Langenberg >> >> <mlangenb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> > Fred, >> >> > I think I could write a patch that will take the file modification >> > date into consideration, but I''m also eager to know, why the check has >> > actually been removed. >> >> > - Matthijs > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matthijs Langenberg
2008-Oct-31 17:40 UTC
Re: Resetting the template or class cache in Rails 2.2.0
After doing some git-bisect magic it seems I''m in some real trouble. Josh Peek intentionally disabled[1] the file modification time check. @Mauricio, are you sure compiled templates are stored on disk? [1] http://github.com/rails/rails/commit/ce5d958f8fe878465c0d2142991a2945ca8d3cd1 On Oct 31, 5:39 pm, "Maurício Linhares" <mauricio.linha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Maybe you could remove the whole compliled templates folder. > > - > Maurício Linhareshttp://alinhavado.wordpress.com/(pt-br) |http://blog.codevader.com/(en) > João Pessoa, PB, +55 83 8867-7208 > > On Fri, Oct 31, 2008 at 1:35 PM, Matthijs Langenberg > > <mlangenb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I don''t understand. If checking if a template has already been > > compiled is thread-safe, checking the modification date should also be > > thread-safe. > > > If thread safety is the issue here, would there be an option for me to > > reset all compiled templates at once? > > > On Oct 31, 2:08 pm, "Maurício Linhares" <mauricio.linha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> My bet is that it isn''t thread-safe. Two actions may check at the same > >> time, both will get a "true" and both will try to update the cache. > > >> - > >> Maurício Linhareshttp://alinhavado.wordpress.com/(pt-br) |http://blog.codevader.com/(en) > >> João Pessoa, PB, +55 83 8867-7208 > > >> On Fri, Oct 31, 2008 at 10:06 AM, Matthijs Langenberg > > >> <mlangenb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> > Fred, > > >> > I think I could write a patch that will take the file modification > >> > date into consideration, but I''m also eager to know, why the check has > >> > actually been removed. > > >> > - Matthijs--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi guys, I''m trying to get themes working in my app. I''m using the prepend_view_path in a before filter. Everything seems to work great.. however, it won''t render layouts from the theme location.. it only renders the rest of the view files from the theme location and the layouts are from the default /app/views location.. Any ideas on how to solve this? I''m using the Rails 2.3RC1.. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---