Add changeset comment query limit settings; use common query limit in changeset comment feeds
This commit is contained in:
parent
d92fc6e526
commit
989b110bfc
3 changed files with 14 additions and 20 deletions
|
@ -1,5 +1,7 @@
|
||||||
module ChangesetComments
|
module ChangesetComments
|
||||||
class FeedsController < ApplicationController
|
class FeedsController < ApplicationController
|
||||||
|
include QueryMethods
|
||||||
|
|
||||||
before_action :authorize_web
|
before_action :authorize_web
|
||||||
before_action :set_locale
|
before_action :set_locale
|
||||||
|
|
||||||
|
@ -19,10 +21,13 @@ module ChangesetComments
|
||||||
changeset = Changeset.find(changeset_id)
|
changeset = Changeset.find(changeset_id)
|
||||||
|
|
||||||
# Return comments for this changeset only
|
# Return comments for this changeset only
|
||||||
@comments = changeset.comments.includes(:author, :changeset).reverse_order.limit(comments_limit)
|
@comments = changeset.comments.includes(:author, :changeset).reverse_order
|
||||||
|
@comments = query_limit(@comments)
|
||||||
else
|
else
|
||||||
# Return comments
|
# Return comments
|
||||||
@comments = ChangesetComment.includes(:author, :changeset).where(:visible => true).order("created_at DESC").limit(comments_limit).preload(:changeset)
|
@comments = ChangesetComment.includes(:author, :changeset).where(:visible => true).order("created_at DESC")
|
||||||
|
@comments = query_limit(@comments)
|
||||||
|
@comments = @comments.preload(:changeset)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Render the result
|
# Render the result
|
||||||
|
@ -32,21 +37,5 @@ module ChangesetComments
|
||||||
rescue OSM::APIBadUserInput
|
rescue OSM::APIBadUserInput
|
||||||
head :bad_request
|
head :bad_request
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
##
|
|
||||||
# Get the maximum number of comments to return
|
|
||||||
def comments_limit
|
|
||||||
if params[:limit]
|
|
||||||
if params[:limit].to_i.positive? && params[:limit].to_i <= 10000
|
|
||||||
params[:limit].to_i
|
|
||||||
else
|
|
||||||
raise OSM::APIBadUserInput, "Comments limit must be between 1 and 10000"
|
|
||||||
end
|
|
||||||
else
|
|
||||||
100
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,8 +12,9 @@ module QueryMethods
|
||||||
##
|
##
|
||||||
# Get query limit value from request parameters and settings
|
# Get query limit value from request parameters and settings
|
||||||
def query_limit_value
|
def query_limit_value
|
||||||
max_limit = Settings["max_#{controller_name.singularize}_query_limit"]
|
name = controller_path.sub(%r{^api/}, "").tr("/", "_").singularize
|
||||||
default_limit = Settings["default_#{controller_name.singularize}_query_limit"]
|
max_limit = Settings["max_#{name}_query_limit"]
|
||||||
|
default_limit = Settings["default_#{name}_query_limit"]
|
||||||
if params[:limit]
|
if params[:limit]
|
||||||
if params[:limit].to_i.positive? && params[:limit].to_i <= max_limit
|
if params[:limit].to_i.positive? && params[:limit].to_i <= max_limit
|
||||||
params[:limit].to_i
|
params[:limit].to_i
|
||||||
|
|
|
@ -35,6 +35,10 @@ tracepoints_per_page: 5000
|
||||||
default_changeset_query_limit: 100
|
default_changeset_query_limit: 100
|
||||||
# Maximum limit on the number of changesets returned by the changeset query api method
|
# Maximum limit on the number of changesets returned by the changeset query api method
|
||||||
max_changeset_query_limit: 100
|
max_changeset_query_limit: 100
|
||||||
|
# Default limit on the number of changeset comments in feeds
|
||||||
|
default_changeset_comments_feed_query_limit: 100
|
||||||
|
# Maximum limit on the number of changesets comments in feeds
|
||||||
|
max_changeset_comments_feed_query_limit: 10000
|
||||||
# Maximum number of nodes that will be returned by the api in a map request
|
# Maximum number of nodes that will be returned by the api in a map request
|
||||||
max_number_of_nodes: 50000
|
max_number_of_nodes: 50000
|
||||||
# Maximum number of nodes that can be in a way (checked on save)
|
# Maximum number of nodes that can be in a way (checked on save)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue