|
|
@ -16,17 +16,18 @@ import ( |
|
|
|
var updateTask = task.New(time.Second*60, RunFullUpdate) |
|
|
|
|
|
|
|
// UpdateCharacters updates the characters for the given log.
|
|
|
|
func UpdateCharacters(log models.Log, addUnknowns bool) (models.Log, error) { |
|
|
|
func UpdateCharacters(log models.Log, unknowns map[string]int) (models.Log, error) { |
|
|
|
posts, err := posts.List(&posts.Filter{LogID: &log.ShortID, Kind: []string{"action", "text", "chars"}, Limit: 0}) |
|
|
|
if err != nil { |
|
|
|
return models.Log{}, err |
|
|
|
} |
|
|
|
|
|
|
|
counts := make(map[string]int) |
|
|
|
added := make(map[string]bool) |
|
|
|
removed := make(map[string]bool) |
|
|
|
for _, post := range posts { |
|
|
|
if post.Kind == "text" || post.Kind == "action" { |
|
|
|
if strings.HasPrefix(post.Text, "(") || strings.Contains(post.Nick, "(") || strings.Contains(post.Nick, "[E]") { |
|
|
|
if strings.HasPrefix(post.Text, "(") || strings.Contains(post.Nick, "(") || strings.Contains(post.Nick, "[E]") || strings.HasSuffix(post.Nick, "|") { |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
@ -38,6 +39,7 @@ func UpdateCharacters(log models.Log, addUnknowns bool) (models.Log, error) { |
|
|
|
} |
|
|
|
|
|
|
|
added[post.Nick] = true |
|
|
|
counts[post.Nick]++ |
|
|
|
} |
|
|
|
if post.Kind == "chars" { |
|
|
|
tokens := strings.Fields(post.Text) |
|
|
@ -79,7 +81,7 @@ func UpdateCharacters(log models.Log, addUnknowns bool) (models.Log, error) { |
|
|
|
|
|
|
|
log.CharacterIDs = characterIDs |
|
|
|
|
|
|
|
if addUnknowns { |
|
|
|
if len(nicks) > 0 && unknowns != nil { |
|
|
|
NickLoop: |
|
|
|
for nick := range added { |
|
|
|
if !added[nick] { |
|
|
@ -92,7 +94,7 @@ func UpdateCharacters(log models.Log, addUnknowns bool) (models.Log, error) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
unknownnicks.Add(nick) |
|
|
|
unknowns[nick] += counts[nick] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -107,27 +109,22 @@ func RunFullUpdate() error { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
err = unknownnicks.BeginUpdate() |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
unknowns := make(map[string]int, 256) |
|
|
|
|
|
|
|
log := models.Log{} |
|
|
|
for iter.Next(&log) { |
|
|
|
_, err = UpdateCharacters(log, true) |
|
|
|
_, err = UpdateCharacters(log, unknowns) |
|
|
|
if err != nil { |
|
|
|
unknownnicks.CancelUpdate() |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
err = iter.Err() |
|
|
|
if err != nil { |
|
|
|
unknownnicks.CancelUpdate() |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
err = unknownnicks.CommitUpdate() |
|
|
|
err = unknownnicks.Update(unknowns) |
|
|
|
if err != nil { |
|
|
|
return errors.New("Failed to commit unknown nicks update: " + err.Error()) |
|
|
|
} |
|
|
|