Fix #4614: Counts endpoint responds with invalid JSON.
Caused by the search timing out and returning nil for the count. Nil got serialized as the empty string instead of as null.
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
class CountsController < ApplicationController
|
||||
respond_to :xml, :json
|
||||
respond_to :html, :xml, :json
|
||||
|
||||
def posts
|
||||
estimate_count = params.fetch(:estimate_count, "true").truthy?
|
||||
skip_cache = params.fetch(:skip_cache, "false").truthy?
|
||||
@count = PostQueryBuilder.new(params[:tags], CurrentUser.user).normalized_query.fast_count(timeout: CurrentUser.statement_timeout, estimate_count: estimate_count, skip_cache: skip_cache)
|
||||
|
||||
if request.format.xml?
|
||||
respond_with({ posts: @count }, root: "counts")
|
||||
else
|
||||
respond_with({ counts: { posts: @count }})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user