mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-08 15:05:22 +02:00
MaxRowCountExceededError
This commit is contained in:
parent
62160facb5
commit
0522fe2910
3 changed files with 19 additions and 2 deletions
|
@ -5,6 +5,8 @@ class ImportsController < ApplicationController
|
||||||
@import.publish_later
|
@import.publish_later
|
||||||
|
|
||||||
redirect_to import_path(@import), notice: "Your import has started in the background."
|
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
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
class AccountImport < Import
|
class AccountImport < Import
|
||||||
def import!
|
def import!
|
||||||
raise "Account import is limited to 50 rows" if rows.count > 50
|
|
||||||
|
|
||||||
transaction do
|
transaction do
|
||||||
rows.each do |row|
|
rows.each do |row|
|
||||||
mapping = mappings.account_types.find_by(key: row.entity_type)
|
mapping = mappings.account_types.find_by(key: row.entity_type)
|
||||||
|
@ -56,4 +54,8 @@ class AccountImport < Import
|
||||||
|
|
||||||
CSV.parse(template, headers: true)
|
CSV.parse(template, headers: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def max_row_count
|
||||||
|
50
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
class Import < ApplicationRecord
|
class Import < ApplicationRecord
|
||||||
|
MaxRowCountExceededError = Class.new(StandardError)
|
||||||
|
|
||||||
TYPES = %w[TransactionImport TradeImport AccountImport MintImport].freeze
|
TYPES = %w[TransactionImport TradeImport AccountImport MintImport].freeze
|
||||||
SIGNAGE_CONVENTIONS = %w[inflows_positive inflows_negative]
|
SIGNAGE_CONVENTIONS = %w[inflows_positive inflows_negative]
|
||||||
SEPARATORS = [ [ "Comma (,)", "," ], [ "Semicolon (;)", ";" ] ].freeze
|
SEPARATORS = [ [ "Comma (,)", "," ], [ "Semicolon (;)", ";" ] ].freeze
|
||||||
|
@ -52,6 +54,7 @@ class Import < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def publish_later
|
def publish_later
|
||||||
|
raise MaxRowCountExceededError if row_count_exceeded?
|
||||||
raise "Import is not publishable" unless publishable?
|
raise "Import is not publishable" unless publishable?
|
||||||
|
|
||||||
update! status: :importing
|
update! status: :importing
|
||||||
|
@ -60,6 +63,8 @@ class Import < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def publish
|
def publish
|
||||||
|
raise MaxRowCountExceededError if row_count_exceeded?
|
||||||
|
|
||||||
import!
|
import!
|
||||||
|
|
||||||
family.sync_later
|
family.sync_later
|
||||||
|
@ -220,7 +225,15 @@ class Import < ApplicationRecord
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def max_row_count
|
||||||
|
10000
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def row_count_exceeded?
|
||||||
|
rows.count > max_row_count
|
||||||
|
end
|
||||||
|
|
||||||
def import!
|
def import!
|
||||||
# no-op, subclasses can implement for customization of algorithm
|
# no-op, subclasses can implement for customization of algorithm
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue