Skip to content

Commit

Permalink
remove status from count filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Sledro committed Nov 13, 2024
1 parent f7b9e59 commit 91c63b9
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions database/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,42 @@ func (db *Database) GetTransactions(ctx context.Context, filter models.Filter, p
return nil, fmt.Errorf("failed to get total count: %w", err)
}

// Create base filter without status but keeping all other filters
baseFilter := bson.D{}
for k, v := range mongoFilter {
if k != "status" {
baseFilter = append(baseFilter, bson.E{Key: k, Value: v})
}
}

actionNeededFilter := bson.D{
{Key: "$and", Value: bson.A{
mongoFilter,
baseFilter, // Use baseFilter instead of mongoFilter
bson.D{{Key: "status", Value: bson.M{
"$in": []string{
string(types.ReadyToProve),
string(types.ReadyForRelay),
},
}},
}},
}}
}}},
}},
}
actionNeededCount, err := collection.CountDocuments(ctx, actionNeededFilter)
if err != nil {
return nil, fmt.Errorf("failed to get action needed count: %w", err)
}

pendingFilter := bson.D{
{Key: "$and", Value: bson.A{
mongoFilter,
baseFilter, // Use baseFilter instead of mongoFilter
bson.D{{Key: "status", Value: bson.M{
"$in": []string{
string(types.UnconfirmedL1ToL2Message),
string(types.StateRootNotPublished),
string(types.InChallengePeriod),
},
}},
}},
}}
}}},
}},
}
pendingCount, err := collection.CountDocuments(ctx, pendingFilter)
if err != nil {
return nil, fmt.Errorf("failed to get pending count: %w", err)
Expand Down

0 comments on commit 91c63b9

Please sign in to comment.