Skip to content

Commit

Permalink
Reorder query pipeline to leverage indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
Agustin Godnic committed Aug 1, 2023
1 parent 9b9b237 commit ba4740b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions api/handlers/vaa/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ func (r *Repository) FindVaasByEmitterAndToChain(
// build a query pipeline based on input parameters
var pipeline mongo.Pipeline
{
// specify sorting criteria
pipeline = append(pipeline, bson.D{{"$sort", bson.D{bson.E{"indexedAt", query.GetSortInt()}}}})

// filter by emitterChain, emitterAddr, and toChain
pipeline = append(pipeline, bson.D{
{"$match", bson.D{bson.E{"emitterChain", query.chainId}}},
Expand All @@ -140,6 +137,9 @@ func (r *Repository) FindVaasByEmitterAndToChain(
{"$match", bson.D{bson.E{"rawStandardizedProperties.toChain", toChain}}},
})

// specify sorting criteria
pipeline = append(pipeline, bson.D{{"$sort", bson.D{bson.E{"indexedAt", query.GetSortInt()}}}})

// skip initial results
if query.Pagination.Skip != 0 {
pipeline = append(pipeline, bson.D{{"$skip", query.Pagination.Skip}})
Expand Down

0 comments on commit ba4740b

Please sign in to comment.