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.
This commit is contained in:
@@ -1095,16 +1095,16 @@ class Post < ApplicationRecord
|
|||||||
# quantities being off by a few hundred doesn't matter much
|
# quantities being off by a few hundred doesn't matter much
|
||||||
if Danbooru.config.estimate_post_counts
|
if Danbooru.config.estimate_post_counts
|
||||||
if tags == ""
|
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)?$/
|
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)?$/
|
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)?$/
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user