Gisle Aune
5 years ago
7 changed files with 62 additions and 95 deletions
-
18graph2/resolvers/unknownnicks.go
-
37models/unknownnicks/db.go
-
10models/unknownnicks/list.go
-
1models/unknownnicks/remove.go
-
22models/unknownnicks/update.go
-
65services/logs.go
-
2services/services.go
@ -1,37 +0,0 @@ |
|||
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) |
|||
} |
|||
}) |
|||
} |
@ -1,10 +0,0 @@ |
|||
package unknownnicks |
|||
|
|||
import ( |
|||
"git.aiterp.net/rpdata/api/models" |
|||
) |
|||
|
|||
// List lists the top N unknown nicks.
|
|||
func List(limit int) ([]models.UnknownNick, error) { |
|||
return list(nil, limit) |
|||
} |
@ -1 +0,0 @@ |
|||
package unknownnicks |
@ -1,22 +0,0 @@ |
|||
package unknownnicks |
|||
|
|||
import ( |
|||
"github.com/globalsign/mgo/bson" |
|||
) |
|||
|
|||
// Update updates the map, replacing it with the scores provided here.
|
|||
func Update(updateMap map[string]int) error { |
|||
_, err := collection.RemoveAll(bson.M{}) |
|||
if err != nil { |
|||
return err |
|||
} |
|||
|
|||
for nick, score := range updateMap { |
|||
_, err := collection.UpsertId(nick, bson.M{"$set": bson.M{"score": score}}) |
|||
if err != nil { |
|||
return err |
|||
} |
|||
} |
|||
|
|||
return nil |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue