Skip to content

Commit 15c7481

Browse files
Copilotblocknotes
andauthored
fix: cap CsvExport rows at configurable limit (default 10_000)
Agent-Logs-Url: https://github.com/blocknotes/tiny_admin/sessions/701f4f0e-0369-4a49-ab32-a89eefb32223 Co-authored-by: blocknotes <6893256+blocknotes@users.noreply.github.com>
1 parent cdd2b85 commit 15c7481

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

lib/tiny_admin/actions/csv_export.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ module Actions
1717
# The action respects the resource's +index.attributes+ config for the
1818
# columns to export. If no attributes are configured, all repository fields
1919
# are exported.
20+
#
21+
# Use the +max_export_limit+ option to cap the number of rows returned (default: 10_000).
22+
# Set it to nil to disable the cap (not recommended for large datasets).
2023
class CsvExport < BasicAction
24+
DEFAULT_MAX_EXPORT_LIMIT = 10_000
25+
2126
def call(app:, context:, options:)
2227
repository = context.repository
2328
fields_options = attribute_options(options[:attributes])
@@ -33,8 +38,10 @@ def call(app:, context:, options:)
3338
private
3439

3540
def fetch_all_records(repository, filters, options)
36-
# Fetch all matching records without pagination
37-
records, = repository.list(page: 1, limit: Float::INFINITY.to_i, filters: filters, sort: options[:sort])
41+
limit = options.key?(:max_export_limit) ? options[:max_export_limit] : DEFAULT_MAX_EXPORT_LIMIT
42+
# When limit is nil, fetch all records (use with caution on large datasets).
43+
effective_limit = limit || repository.list(page: 1, limit: 1).last
44+
records, = repository.list(page: 1, limit: effective_limit, filters: filters, sort: options[:sort])
3845
records
3946
end
4047

0 commit comments

Comments
 (0)