1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-08 15:05:22 +02:00

MaxRowCountExceededError

This commit is contained in:
Zach Gollwitzer 2025-05-18 14:55:18 -04:00
parent 62160facb5
commit 0522fe2910
3 changed files with 19 additions and 2 deletions

View file

@ -5,6 +5,8 @@ class ImportsController < ApplicationController
@import.publish_later
redirect_to import_path(@import), notice: "Your import has started in the background."
rescue Import::MaxRowCountExceededError
redirect_back_or_to import_path(@import), alert: "Your import exceeds the maximum row count of #{@import.max_row_count}."
end
def index

View file

@ -1,7 +1,5 @@
class AccountImport < Import
def import!
raise "Account import is limited to 50 rows" if rows.count > 50
transaction do
rows.each do |row|
mapping = mappings.account_types.find_by(key: row.entity_type)
@ -56,4 +54,8 @@ class AccountImport < Import
CSV.parse(template, headers: true)
end
def max_row_count
50
end
end

View file

@ -1,4 +1,6 @@
class Import < ApplicationRecord
MaxRowCountExceededError = Class.new(StandardError)
TYPES = %w[TransactionImport TradeImport AccountImport MintImport].freeze
SIGNAGE_CONVENTIONS = %w[inflows_positive inflows_negative]
SEPARATORS = [ [ "Comma (,)", "," ], [ "Semicolon (;)", ";" ] ].freeze
@ -52,6 +54,7 @@ class Import < ApplicationRecord
end
def publish_later
raise MaxRowCountExceededError if row_count_exceeded?
raise "Import is not publishable" unless publishable?
update! status: :importing
@ -60,6 +63,8 @@ class Import < ApplicationRecord
end
def publish
raise MaxRowCountExceededError if row_count_exceeded?
import!
family.sync_later
@ -220,7 +225,15 @@ class Import < ApplicationRecord
)
end
def max_row_count
10000
end
private
def row_count_exceeded?
rows.count > max_row_count
end
def import!
# no-op, subclasses can implement for customization of algorithm
end