Browse Source

graph2: Added unknownNick query

module-madness-pointers
Gisle Aune 6 years ago
parent
commit
80e6c048c9
  1. 2
      graph2/gqlgen.yml
  2. 23
      graph2/queries/unknownnicks.go
  3. 4
      graph2/schema/root.gql
  4. 20
      graph2/schema/types/UnknownNick.gql
  5. 4
      models/unknown-nick.go
  6. 2
      models/unknownnicks/db.go
  7. 4
      models/unknownnicks/update.go

2
graph2/gqlgen.yml

@ -23,6 +23,8 @@ models:
model: git.aiterp.net/rpdata/api/models.Channel model: git.aiterp.net/rpdata/api/models.Channel
ChannelsFilter: ChannelsFilter:
model: git.aiterp.net/rpdata/api/models/channels.Filter model: git.aiterp.net/rpdata/api/models/channels.Filter
UnknownNick:
model: git.aiterp.net/rpdata/api/models.UnknownNick
Post: Post:
model: git.aiterp.net/rpdata/api/models.Post model: git.aiterp.net/rpdata/api/models.Post
PostsFilter: PostsFilter:

23
graph2/queries/unknownnicks.go

@ -0,0 +1,23 @@
package queries
import (
"context"
"git.aiterp.net/rpdata/api/models"
"git.aiterp.net/rpdata/api/models/unknownnicks"
"git.aiterp.net/rpdata/api/graph2/input"
)
/// Queries
func (r *resolver) UnknownNicks(ctx context.Context, filter *input.UnknownNicksFilter) ([]models.UnknownNick, error) {
limit := 100
if filter != nil {
if filter.Limit > 0 {
limit = filter.Limit
}
}
return unknownnicks.List(limit)
}

4
graph2/schema/root.gql

@ -26,6 +26,10 @@ type Query {
posts(filter: PostsFilter): [Post!]! posts(filter: PostsFilter): [Post!]!
"List unknown nicks"
unknownNicks(filter: UnknownNicksFilter): [UnknownNick!]!
# Find log by ID # Find log by ID
log(id: String!): Log! log(id: String!): Log!

20
graph2/schema/types/UnknownNick.gql

@ -0,0 +1,20 @@
"""
An unknown nick is a nick found by the logbot that's not associated with
any characters. Many are going to be false positives, but most should be
useful in pointing out which characters are missing.
"""
type UnknownNick {
"The IRC nick that's unknown."
nick: String!
"The amount of logs that contains the unknown nick."
score: Int!
}
"""
Input for the unknownNicks query.
"""
input UnknownNicksFilter {
"The highest amount of unknown nicks to return."
limit: Int!
}

4
models/unknown-nick.go

@ -2,6 +2,6 @@ package models
// UnknownNick represents an unknown nick name. // UnknownNick represents an unknown nick name.
type UnknownNick struct { type UnknownNick struct {
Nick string `bson:"_id"`
Weight int `bson:"weight"`
Nick string `bson:"_id"`
Score int `bson:"score"`
} }

2
models/unknownnicks/db.go

@ -17,7 +17,7 @@ func list(query interface{}, limit int) ([]models.UnknownNick, error) {
} }
posts := make([]models.UnknownNick, 0, size) posts := make([]models.UnknownNick, 0, size)
err := collection.Find(query).Limit(limit).Sort("weight").All(&posts)
err := collection.Find(query).Limit(limit).Sort("-score").All(&posts)
if err != nil { if err != nil {
return nil, err return nil, err
} }

4
models/unknownnicks/update.go

@ -44,8 +44,8 @@ func CancelUpdate() {
func CommitUpdate() error { func CommitUpdate() error {
defer updateMutex.Unlock() defer updateMutex.Unlock()
for nick, weight := range updateMap {
_, err := collection.UpsertId(nick, bson.M{"$set": bson.M{"weight": weight}})
for nick, score := range updateMap {
_, err := collection.UpsertId(nick, bson.M{"$set": bson.M{"score": score}})
if err != nil { if err != nil {
return err return err
} }

Loading…
Cancel
Save