@@ -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