DEV: set limit for maximum no of rows in CSV exports.

This commit is contained in:
Vinoth Kannan 2020-02-20 23:34:15 +05:30
parent 277346b097
commit 183bc26763
1 changed files with 9 additions and 6 deletions

View File

@ -23,7 +23,8 @@ end
add_admin_route 'explorer.title', 'explorer' add_admin_route 'explorer.title', 'explorer'
module ::DataExplorer module ::DataExplorer
QUERY_RESULT_MAX_LIMIT = 1000 QUERY_RESULT_DEFAULT_LIMIT = 1000
QUERY_RESULT_MAX_LIMIT = 10000
def self.plugin_name def self.plugin_name
'discourse-data-explorer'.freeze 'discourse-data-explorer'.freeze
@ -130,7 +131,7 @@ after_initialize do
WITH query AS ( WITH query AS (
#{query.sql} #{query.sql}
) SELECT * FROM query ) SELECT * FROM query
LIMIT #{opts[:limit] || DataExplorer::QUERY_RESULT_MAX_LIMIT} LIMIT #{opts[:limit] || DataExplorer::QUERY_RESULT_DEFAULT_LIMIT}
SQL SQL
time_start = Time.now time_start = Time.now
@ -1179,10 +1180,12 @@ SQL
opts[:explain] = true if params[:explain] == "true" opts[:explain] = true if params[:explain] == "true"
opts[:limit] = opts[:limit] =
if params[:limit] == "ALL" || params[:format] == "csv" if params[:limit]
"ALL"
elsif params[:limit]
params[:limit].to_i params[:limit].to_i
elsif params[:format] == "csv"
DataExplorer::QUERY_RESULT_MAX_LIMIT
elsif params[:limit] == "ALL"
"ALL"
end end
result = DataExplorer.run_query(query, query_params, opts) result = DataExplorer.run_query(query, query_params, opts)
@ -1220,7 +1223,7 @@ SQL
result_count: pg_result.values.length || 0, result_count: pg_result.values.length || 0,
params: query_params, params: query_params,
columns: cols, columns: cols,
default_limit: DataExplorer::QUERY_RESULT_MAX_LIMIT default_limit: DataExplorer::QUERY_RESULT_DEFAULT_LIMIT
} }
json[:explain] = result[:explain] if opts[:explain] json[:explain] = result[:explain] if opts[:explain]