Skip to content

Commit

Permalink
Fix transaction enrichment query to use correct table references
Browse files Browse the repository at this point in the history
- Update queries to explicitly join and reference account_entries and account_transactions tables
- Remove unnecessary name presence check before enrichment
- Improve query precision for unenriched transaction selection
  • Loading branch information
Shpigford committed Feb 5, 2025
1 parent e7e76b9 commit 84b2427
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/models/account/data_enricher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def initialize(account)

def run
total_unenriched = account.entries.account_transactions
.where("enriched_at IS NULL OR merchant_id IS NULL OR category_id IS NULL")
.joins(:entryable)
.where("account_entries.enriched_at IS NULL OR account_transactions.merchant_id IS NULL OR account_transactions.category_id IS NULL")
.count

if total_unenriched > 0
Expand All @@ -25,7 +26,8 @@ def run
def enrich_transaction_batch(batch_size = 50, offset = 0)
candidates = account.entries.account_transactions
.includes(entryable: [ :merchant, :category ])
.where("enriched_at IS NULL OR merchant_id IS NULL OR category_id IS NULL")
.joins(:entryable)
.where("account_entries.enriched_at IS NULL OR account_transactions.merchant_id IS NULL OR account_transactions.category_id IS NULL")
.offset(offset)
.limit(batch_size)

Expand All @@ -35,8 +37,6 @@ def enrich_transaction_batch(batch_size = 50, offset = 0)

candidates.each do |entry|
begin
next unless entry.name.present?

info = self.class.synth_provider.enrich_transaction(entry.name).info

next unless info.present?
Expand Down

0 comments on commit 84b2427

Please sign in to comment.