GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
864 B

  1. package changes
  2. import (
  3. "log"
  4. "sync"
  5. "time"
  6. "git.aiterp.net/rpdata/api/internal/store"
  7. "git.aiterp.net/rpdata/api/models"
  8. "github.com/globalsign/mgo"
  9. "github.com/globalsign/mgo/bson"
  10. )
  11. var collection *mgo.Collection
  12. var submitMutex sync.Mutex
  13. func list(query bson.M, limit int) ([]models.Change, error) {
  14. changes := make([]models.Change, 0, 64)
  15. err := collection.Find(query).Limit(limit).Sort("-date").All(&changes)
  16. return changes, err
  17. }
  18. func init() {
  19. store.HandleInit(func(db *mgo.Database) {
  20. collection = db.C("common.changes")
  21. collection.EnsureIndexKey("date")
  22. collection.EnsureIndexKey("author")
  23. collection.EnsureIndexKey("keys")
  24. err := collection.EnsureIndex(mgo.Index{
  25. Name: "expiry",
  26. Key: []string{"date"},
  27. ExpireAfter: time.Hour * 2400, // 100 days
  28. })
  29. if err != nil {
  30. log.Fatalln(err)
  31. }
  32. })
  33. }