mirror of
https://github.com/we-promise/sure.git
synced 2026-06-08 12:19:03 +00:00
perf(transactions): preload new form options (#2189)
* perf(transactions): preload new form options * refactor(transactions): reuse new form account scope
This commit is contained in:
@@ -9,9 +9,7 @@ class TransactionsController < ApplicationController
|
||||
prefill_params_from_duplicate!
|
||||
super
|
||||
apply_duplicate_attributes!
|
||||
@income_categories = Current.family.categories.incomes.alphabetically
|
||||
@expense_categories = Current.family.categories.expenses.alphabetically
|
||||
@categories = Current.family.categories.alphabetically
|
||||
set_new_transaction_form_options
|
||||
end
|
||||
|
||||
def index
|
||||
@@ -117,6 +115,7 @@ class TransactionsController < ApplicationController
|
||||
format.turbo_stream { stream_redirect_back_or_to(account_path(@entry.account)) }
|
||||
end
|
||||
else
|
||||
set_new_transaction_form_options
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
@@ -489,6 +488,21 @@ class TransactionsController < ApplicationController
|
||||
set_entry
|
||||
end
|
||||
|
||||
def set_new_transaction_form_options
|
||||
accessible_accounts_scope = accessible_accounts
|
||||
|
||||
@account_currencies = accessible_accounts_scope.pluck(:id, :currency).to_h
|
||||
@manual_accounts = accessible_accounts_scope
|
||||
.manual
|
||||
.active
|
||||
.alphabetically
|
||||
.includes(:account_providers, logo_attachment: :blob)
|
||||
.to_a
|
||||
@categories = Current.family.categories.alphabetically.to_a
|
||||
@merchants = Current.family.available_merchants_for(Current.user).alphabetically.to_a
|
||||
@tags = Current.family.tags.alphabetically.to_a
|
||||
end
|
||||
|
||||
# Filters entry_params based on the user's permission on the account.
|
||||
# read_write users can only annotate (category, tags, notes, merchant).
|
||||
# read_only users cannot update anything.
|
||||
|
||||
Reference in New Issue
Block a user