Perf: Add composite database indexes for common queries

Add indexes for:
- (AccountId, Category) - account spending by category
- (AccountId, Date) - account transaction timelines
- (MerchantId, Date) - merchant spending trends
- (CardId, Date) - card activity analysis
- FileHashSha256 on Receipts - duplicate detection
- (TransactionId, ReceiptDate) on Receipts - receipt lookups

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-24 21:11:05 -05:00
parent 53c674c6e0
commit 1de3920db4
4 changed files with 732 additions and 4 deletions

View File

@@ -195,6 +195,16 @@ namespace MoneyMap.Data
modelBuilder.Entity<Transaction>().HasIndex(x => x.Amount);
modelBuilder.Entity<Transaction>().HasIndex(x => x.Category);
modelBuilder.Entity<Transaction>().HasIndex(x => x.MerchantId);
// Composite indexes for common query patterns
modelBuilder.Entity<Transaction>().HasIndex(x => new { x.AccountId, x.Category });
modelBuilder.Entity<Transaction>().HasIndex(x => new { x.AccountId, x.Date });
modelBuilder.Entity<Transaction>().HasIndex(x => new { x.MerchantId, x.Date });
modelBuilder.Entity<Transaction>().HasIndex(x => new { x.CardId, x.Date });
// Receipt duplicate detection and lookup
modelBuilder.Entity<Receipt>().HasIndex(x => x.FileHashSha256);
modelBuilder.Entity<Receipt>().HasIndex(x => new { x.TransactionId, x.ReceiptDate });
}
}
}