search: refactor fast_count to return nil on timeout.
* Refactor fast_count to return nil instead of 1,000,000 if the exact count times out. * Remove the estimate_post_counts and blank_tag_search_fast_count global config options. * Replace the hardcoded post count estimates inside fast_count with a method that parses Postgres's estimated row count from EXPLAIN. * /counts/posts.json: ** Remove the `raise_on_timeout` parameter. ** Add an `estimate_count=<true|false>` parameter. ** Return null instead of 1,000,000 if the exact count times out.
This commit is contained in:
15
app/logical/explain_parser.rb
Normal file
15
app/logical/explain_parser.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class ExplainParser < Struct.new(:sql)
|
||||
extend Memoist
|
||||
|
||||
def query_plan
|
||||
result = ApplicationRecord.connection.select_one("EXPLAIN (FORMAT JSON) #{sql}")
|
||||
json = JSON.parse(result["QUERY PLAN"])
|
||||
json.first["Plan"]
|
||||
end
|
||||
|
||||
def row_count
|
||||
query_plan["Plan Rows"]
|
||||
end
|
||||
|
||||
memoize :query_plan
|
||||
end
|
||||
Reference in New Issue
Block a user