Skip to content

Commit

Permalink
feat: add mongo indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Nov 29, 2022
1 parent 8ad10d9 commit dcfbe0a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/nemeton/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,29 @@ func (s *Store) init(ctx context.Context) error {
s.phases = append(s.phases, &phase)
}

if err := s.ensureIndexes(ctx); err != nil {
return err
}
return nil
}

func (s *Store) ensureIndexes(ctx context.Context) error {
_, err := s.db.Collection(validatorsCollectionName).
Indexes().
CreateMany(
ctx,
[]mongo.IndexModel{
{Keys: bson.M{"points": 1}},
{Keys: bson.M{"moniker": 1}},
{Keys: bson.M{"valoper": 1}, Options: options.Index().SetUnique(true)},
{Keys: bson.M{"delegator": 1}, Options: options.Index().SetUnique(true)},
{Keys: bson.M{"twitter": 1}, Options: options.Index().SetUnique(true)},
{Keys: bson.M{"discord": 1}, Options: options.Index().SetUnique(true)},
},
)
return err
}

func (s *Store) GetPhase(number int) *Phase {
for _, phase := range s.phases {
if phase.Number == number {
Expand Down

0 comments on commit dcfbe0a

Please sign in to comment.