“after_filter”如何/何时运行? [英] How/when the 'after_filter' works/runs?
问题描述
我正在使用Ruby on Rails 3.1,我想知道(对于 performance 原因) after_filter
在该视图之后运行文件被渲染。也就是说,当用户访问我的应用程序的URL时,他/她应该显示的相关视图文件在 after_filter
运行或者 after_filter
在视图文件被渲染之前运行?
换句话说, application > server 在运行 after_filter
之前开始向用户发送呈现的视图数据,或者等待运行 after_filter
方法,然后才发送该视图数据?
:我打开这个问题,因为我想运行一些系统更新( note :这些更新不会影响视图输出数据,并且不会被/用于视图),而不会影响最终用户体验例如:缓慢加载我的应用程序网页)。
您必须知道,一致并运行在自己的线程中。
如果你把代码放在 after_filter
中,这会延迟整个请求:总结不好,如果线程还活着,页面是这就是为什么你找到像 DelayedJob
和 Resque
,它们在并行进程中工作,不会影响你的应用程序。
要回答你原来的问题, after_filter
在处理完视图后触发。
这有时是一个麻烦,所以人们创建了一些 before_render
过滤器。
I am using Ruby on Rails 3.1 and I would like to know (for performance reasons) whether or not the after_filter
runs after that view files are rendered. That is, when an user access a my application URL, the related view file that he/she should display is rendered before that the after_filter
runs or the after_filter
runs before that the view file is rendered?
In other words, the application server starts to send the rendered view data to the user before to run the after_filter
or it waits to run the after_filter
method and only then it sends that view data?
P.S.: I opened this question because I would like to run some system updates (note: these updates doesn't affect the view output data and are not "used by"/"necessary to" the view at all) without impact on the end user experience (for example: slow loading of my application Web pages).
You have to be aware that a request to your server is fully consistent and runs in its own thread.
If you put code in an after_filter
, this will delay the whole request: to sum up badly, if the thread is alive, the page is not delivered.
That's why you find great plugins like DelayedJob
and Resque
, they work in a parallel processes and won't affect your app.
To answer your original question , after_filter
are triggered after the view has been processed.
This is sometimes a hassle that's why people created some before_render
filters.
这篇关于“after_filter”如何/何时运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!