MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / processGroupedTransactions

Method processGroupedTransactions

reconciliation.go:828–854  ·  view source on GitHub ↗

processGroupedTransactions handles the matching of transactions for both one-to-many and many-to-one reconciliations. It processes each transaction group in parallel, comparing them to the target transactions. Parameters: - singleTxns: The single transactions (either external or internal). - grouped

(singleTxns []*model.Transaction, groupedTxns map[string][]*model.Transaction, groupMap map[string]bool, matchingRules []model.MatchingRule, isExternalGrouped bool, wg *sync.WaitGroup, matchChan chan model.Match, unMatchChan chan string)

Source from the content-addressed store, hash-verified

826// Returns:
827// - error: If any error occurs during processing.
828func (s *LedgerForge) processGroupedTransactions(singleTxns []*model.Transaction, groupedTxns map[string][]*model.Transaction, groupMap map[string]bool, matchingRules []model.MatchingRule, isExternalGrouped bool, wg *sync.WaitGroup, matchChan chan model.Match, unMatchChan chan string) error {
829 conf, err := config.Fetch()
830 if err != nil {
831 logrus.Errorf("Error fetching configuration: %v", err)
832 }
833 maxWorkers := 10 // Default
834 if conf != nil {
835 maxWorkers = conf.Transaction.MaxWorkers
836 }
837 sem := make(chan struct{}, maxWorkers) // Semaphore to limit concurrency
838
839 for _, singleTxn := range singleTxns {
840 wg.Add(1)
841 go func(txn *model.Transaction) {
842 defer wg.Done()
843 sem <- struct{}{} // Acquire token
844 defer func() { <-sem }() // Release token
845
846 matched := s.matchSingleTransaction(txn, groupedTxns, groupMap, matchingRules, isExternalGrouped, matchChan)
847 if !matched {
848 unMatchChan <- txn.TransactionID
849 }
850 }(singleTxn)
851 }
852
853 return nil
854}
855
856// matchSingleTransaction attempts to match a single transaction with a group of transactions based on matching rules.
857// If a match is found, it sends the match to the match channel and marks the group as processed.

Callers 2

manyToOneMethod · 0.95
oneToManyMethod · 0.95

Calls 2

FetchFunction · 0.92

Tested by

no test coverage detected