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.

37 lines
703 B

  1. package unknownnicks
  2. import (
  3. "log"
  4. "git.aiterp.net/rpdata/api/internal/store"
  5. "git.aiterp.net/rpdata/api/models"
  6. "github.com/globalsign/mgo"
  7. )
  8. var collection *mgo.Collection
  9. func list(query interface{}, limit int) ([]models.UnknownNick, error) {
  10. size := 64
  11. if limit > 0 {
  12. size = limit
  13. }
  14. posts := make([]models.UnknownNick, 0, size)
  15. err := collection.Find(query).Limit(limit).Sort("-score").All(&posts)
  16. if err != nil {
  17. return nil, err
  18. }
  19. return posts, nil
  20. }
  21. func init() {
  22. store.HandleInit(func(db *mgo.Database) {
  23. collection = db.C("logbot3.unkownnicks")
  24. err := collection.EnsureIndexKey("weight")
  25. if err != nil {
  26. log.Fatalln("init logbot3.unkownnicks:", err)
  27. }
  28. })
  29. }