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