作者godfat (godfat 真常)
看板Ruby
标题Re: [问题] after_initialize and after_find
时间Fri Aug 26 07:42:46 2011
※ 引述《tonytonyjan (南洋大兜虫)》之铭言:
: 环境:
: Ruby 1.9.2 Rails 3
: 状况:
: 我在阅读Rails Guide时,发现 after_initialize 和 after_find
: 没有相对的 before_initialize 及 before_find
: 并说要使用时必须以 method define,不能用 handler
: 摘录:
: If you try to register after_initialize or after_find using macro-style class
: methods, they will just be ignored.
: This behaviour is due to performance reasons, since after_initialize and
: after_find will both be called for each record found in the database,
: significantly slowing down the queries.
: 我觉得这样的解释我还是看不太懂
: 1. 这和 self reflection 有关系吗?
这边 self reflection 是指?
: 2. 一个 select query 可能包涵数万笔资料,不管是用 method define 还是 handler
: ,都要被呼叫数万次吧?如此效能还不是一样差吗?
我也觉得没差..... 应该一样,不然就是他写得有问题?
: 3. 对一个 callback 同时使用 method define 和 handler 会导致 handler 被盖掉吗?
实验看看?
: 4. 我想看原始码,但是在github里面有如大海捞针,希望得到众神的指引
你可以直接看电脑里装好的 source, 然後用搜寻的
抱歉现在没有空,所以就先不查也不实验了..
--
In Lisp, you don't just write your program down toward the language,
you also build the language up toward your program.
《Programming Bottom-Up》- Paul Graham 1993
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.135.160.129