Browse Source

fix log importer not refreshing character list.

master 2.0.1
Gisle Aune 4 years ago
parent
commit
6ce38d61b1
  1. 3
      .gitignore
  2. 40
      services/logs.go

3
.gitignore

@ -10,6 +10,9 @@ rpdata-*
.vscode
.idea
/main
/main.exe
/graph2/graphcore/*_gen.go
generated.gql
generated.go

40
services/logs.go

@ -145,26 +145,33 @@ func (s *LogService) Import(ctx context.Context, importer models.LogImporter, da
parsed.Log.EventName = eventName
parsed.Log.ChannelName = channelName
log, err := s.logs.Insert(ctx, parsed.Log)
newLog, err := s.logs.Insert(ctx, parsed.Log)
if err != nil {
return nil, err
}
for _, post := range parsed.Posts {
post.LogID = log.ShortID
post.LogID = newLog.ShortID
}
posts, err := s.posts.InsertMany(ctx, parsed.Posts...)
if err != nil {
_ = s.logs.Delete(ctx, *log)
_ = s.logs.Delete(ctx, *newLog)
return nil, err
}
s.changeService.Submit(ctx, models.ChangeModelLog, "add", true, changekeys.Listed(log), log)
s.changeService.Submit(ctx, models.ChangeModelPost, "add", true, changekeys.Listed(log, posts), log, posts)
s.changeService.Submit(ctx, models.ChangeModelLog, "add", true, changekeys.Listed(newLog), newLog)
s.changeService.Submit(ctx, models.ChangeModelPost, "add", true, changekeys.Listed(newLog, posts), newLog, posts)
refreshedLog, err := s.refreshLogCharacters(ctx, *newLog, nil, false)
if err != nil {
log.Printf("Failed to update characters in newLog %s: %s", newLog.ID, err)
} else {
newLog = refreshedLog
}
results = append(results, log)
results = append(results, newLog)
}
case models.LogImporterForumLog:
{
@ -174,7 +181,7 @@ func (s *LogService) Import(ctx context.Context, importer models.LogImporter, da
}
for _, parsed := range parseResults {
log, err := s.logs.Insert(ctx, parsed.Log)
newLog, err := s.logs.Insert(ctx, parsed.Log)
if err != nil {
return nil, err
}
@ -182,18 +189,27 @@ func (s *LogService) Import(ctx context.Context, importer models.LogImporter, da
parsed.Log.ChannelName = channelName
for _, post := range parsed.Posts {
post.LogID = log.ShortID
post.LogID = newLog.ShortID
}
posts, err := s.posts.InsertMany(ctx, parsed.Posts...)
if err != nil {
_ = s.logs.Delete(ctx, *log)
_ = s.logs.Delete(ctx, *newLog)
return nil, err
return results, err
}
s.changeService.Submit(ctx, models.ChangeModelLog, "add", true, changekeys.Listed(log), log)
s.changeService.Submit(ctx, models.ChangeModelPost, "add", true, changekeys.Listed(log, posts), log, posts)
refreshedLog, err := s.refreshLogCharacters(ctx, *newLog, nil, false)
if err != nil {
log.Printf("Failed to update characters in newLog %s: %s", newLog.ID, err)
} else {
newLog = refreshedLog
}
s.changeService.Submit(ctx, models.ChangeModelLog, "add", true, changekeys.Listed(newLog), newLog)
s.changeService.Submit(ctx, models.ChangeModelPost, "add", true, changekeys.Listed(newLog, posts), newLog, posts)
results = append(results, newLog)
}
}
default:

Loading…
Cancel
Save