是的,没错
我在 rails 5 中发现,any? 和 empty? 都是 select 1
User.where(effective: true).any?
User Exists (0.9ms) SELECT 1 AS one FROM "users" WHERE "users"."deleted_at" IS NULL AND "users"."effective" = $1 LIMIT $2 [["effective", true], ["LIMIT", 1]]
=> true
2.5.1 :005 > User.where(effective: true).empty?
User Exists (0.8ms) SELECT 1 AS one FROM "users" WHERE "users"."deleted_at" IS NULL AND "users"."effective" = $1 LIMIT $2 [["effective", true], ["LIMIT", 1]]
=> false
数据量大的时候,select count(*) 也会慢的吧,而 select 1 会很快
推荐用这个 https://freessl.cn/ 一个提供免费 HTTPS 证书申请的网站,(Let's Encrypt 与 TrustAsia)我刚试了, https://lumao.vicw.com/ 这是我搞的撸猫网,证书有效期 1 年,可以续订,比自己搞简单多了