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
37 lines
703 B
package unknownnicks
|
|
|
|
import (
|
|
"log"
|
|
|
|
"git.aiterp.net/rpdata/api/internal/store"
|
|
"git.aiterp.net/rpdata/api/models"
|
|
"github.com/globalsign/mgo"
|
|
)
|
|
|
|
var collection *mgo.Collection
|
|
|
|
func list(query interface{}, limit int) ([]models.UnknownNick, error) {
|
|
size := 64
|
|
if limit > 0 {
|
|
size = limit
|
|
}
|
|
posts := make([]models.UnknownNick, 0, size)
|
|
|
|
err := collection.Find(query).Limit(limit).Sort("-score").All(&posts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return posts, nil
|
|
}
|
|
|
|
func init() {
|
|
store.HandleInit(func(db *mgo.Database) {
|
|
collection = db.C("logbot3.unkownnicks")
|
|
|
|
err := collection.EnsureIndexKey("weight")
|
|
if err != nil {
|
|
log.Fatalln("init logbot3.unkownnicks:", err)
|
|
}
|
|
})
|
|
}
|