From 8c1ba10314a08bb59caa6044164fb45892bd3c74 Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Fri, 23 May 2025 18:35:42 -0400 Subject: [PATCH] Remove stale code --- .../transactions/category_matcher.rb | 12 ++++ app/models/plaid_item/syncer.rb | 56 ------------------- 2 files changed, 12 insertions(+), 56 deletions(-) diff --git a/app/models/plaid_account/transactions/category_matcher.rb b/app/models/plaid_account/transactions/category_matcher.rb index b3583b54..c4081a68 100644 --- a/app/models/plaid_account/transactions/category_matcher.rb +++ b/app/models/plaid_account/transactions/category_matcher.rb @@ -1,3 +1,15 @@ +# The purpose of this matcher is to auto-match Plaid categories to +# known internal user categories. Since we allow users to define their own +# categories we cannot directly assign Plaid categories as this would overwrite +# user data and create a confusing experience. +# +# Automated category matching in the Maybe app has a hierarchy: +# 1. Naive string matching via CategoryAliasMatcher +# 2. Rules-based matching set by user +# 3. AI-powered matching (also enabled by user via rules) +# +# This class is simply a FAST and CHEAP way to match categories that are high confidence. +# Edge cases will be handled by user-defined rules. class PlaidAccount::Transactions::CategoryMatcher include PlaidAccount::Transactions::CategoryTaxonomy diff --git a/app/models/plaid_item/syncer.rb b/app/models/plaid_item/syncer.rb index 99fec809..b76c37b6 100644 --- a/app/models/plaid_item/syncer.rb +++ b/app/models/plaid_item/syncer.rb @@ -23,60 +23,4 @@ class PlaidItem::Syncer def perform_post_sync # no-op end - - private - def safe_fetch_plaid_data(method) - begin - plaid.send(method, plaid_item) - rescue Plaid::ApiError => e - Rails.logger.warn("Error fetching #{method} for item #{plaid_item.id}: #{e.message}") - nil - end - end - - def handle_plaid_error(error) - error_body = JSON.parse(error.response_body) - - if error_body["error_code"] == "ITEM_LOGIN_REQUIRED" - plaid_item.update!(status: :requires_update) - end - end - - def fetch_and_load_plaid_data - # Investments - fetched_investments = safe_fetch_plaid_data(:get_item_investments) - data[:investments] = fetched_investments || [] - - if fetched_investments - Rails.logger.info "Processing Plaid investments (transactions: #{fetched_investments.transactions.size}, holdings: #{fetched_investments.holdings.size}, securities: #{fetched_investments.securities.size})" - PlaidItem.transaction do - internal_plaid_accounts.each do |internal_plaid_account| - transactions = fetched_investments.transactions.select { |t| t.account_id == internal_plaid_account.plaid_id } - holdings = fetched_investments.holdings.select { |h| h.account_id == internal_plaid_account.plaid_id } - securities = fetched_investments.securities - - internal_plaid_account.sync_investments!(transactions:, holdings:, securities:) - end - end - end - - # Liabilities - fetched_liabilities = safe_fetch_plaid_data(:get_item_liabilities) - data[:liabilities] = fetched_liabilities || [] - - if fetched_liabilities - Rails.logger.info "Processing Plaid liabilities (credit: #{fetched_liabilities.credit&.size || 0}, mortgage: #{fetched_liabilities.mortgage&.size || 0}, student: #{fetched_liabilities.student&.size || 0})" - PlaidItem.transaction do - internal_plaid_accounts.each do |internal_plaid_account| - credit = fetched_liabilities.credit&.find { |l| l.account_id == internal_plaid_account.plaid_id } - mortgage = fetched_liabilities.mortgage&.find { |l| l.account_id == internal_plaid_account.plaid_id } - student = fetched_liabilities.student&.find { |l| l.account_id == internal_plaid_account.plaid_id } - - internal_plaid_account.sync_credit_data!(credit) if credit - internal_plaid_account.sync_mortgage_data!(mortgage) if mortgage - internal_plaid_account.sync_student_loan_data!(student) if student - end - end - end - end end