gpt4 book ai didi

ruby-on-rails - 哪个给我更好的性能 Activerecord find_by 或在哪里?

转载 作者:行者123 更新时间:2023-12-02 17:48:11 25 4
gpt4 key购买 nike

假设我有模型(帐户),其中包含以下列 account_id、user_id、party_id、日期和名称

然后我执行:

Account.find_by_account_id_and_user_id_and_party_id_and_date_and_name(1,2,3,"2012-03-12","Venus")

   Account.where(:account_id => 1, :user_id => 2, :party_id => 3,:date => "2012-03-28",:name => "Venus").limit(1).first

哪个会给我更好的表现?

最佳答案

where 为您提供略微更好的性能。 find_by是通过method_missing魔法实现的; method_missing 需要调用对象的方法表,首先查看是否存在现有方法,如果不存在则调用 method_missing,而 where只是找到正确的方法。

要查看此的实际基准,check out this post .

关于ruby-on-rails - 哪个给我更好的性能 Activerecord find_by 或在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11848708/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com