From b038761fa738ff7d9df30344757c6f8e9933afda Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 16 Dec 2019 18:35:32 -0600 Subject: [PATCH] Post.fast_count: fix post count estimates when there are no posts. Bug: Post.fast_count failed when Danbooru.config.estimate_post_counts was enabled but the database didn't have any posts. This normally happened only during testing. --- app/models/post.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 201bf3263..1dd93e9d5 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1095,16 +1095,16 @@ class Post < ApplicationRecord # quantities being off by a few hundred doesn't matter much if Danbooru.config.estimate_post_counts if tags == "" - return (Post.maximum(:id) * (2200402.0 / 2232212)).floor + return (Post.maximum(:id).to_i * (2200402.0 / 2232212)).floor elsif tags =~ /^rating:s(?:afe)?$/ - return (Post.maximum(:id) * (1648652.0 / 2200402)).floor + return (Post.maximum(:id).to_i * (1648652.0 / 2200402)).floor elsif tags =~ /^rating:q(?:uestionable)?$/ - return (Post.maximum(:id) * (350101.0 / 2200402)).floor + return (Post.maximum(:id).to_i * (350101.0 / 2200402)).floor elsif tags =~ /^rating:e(?:xplicit)?$/ - return (Post.maximum(:id) * (201650.0 / 2200402)).floor + return (Post.maximum(:id).to_i * (201650.0 / 2200402)).floor end end