Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions internal/misc/update_data_sqlc.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ func importPoolsSQLC(ctx context.Context, region string, q *gen.Queries) error {
}
defer resp.Body.Close()
decoder.Token()
skippedMissingShips := 0
for decoder.More() {
var pool struct {
ID uint32 `json:"id"`
Expand All @@ -251,9 +252,14 @@ func importPoolsSQLC(ctx context.Context, region string, q *gen.Queries) error {
return err
}
if tag.RowsAffected() == 0 {
return fmt.Errorf("ship not found for template_id=%d", pool.ID)
skippedMissingShips++
logger.LogEvent("GameData", "Updating", fmt.Sprintf("skipping pool mapping for missing ship template_id=%d (region=%s)", pool.ID, region), logger.LOG_LEVEL_WARN)
continue
}
}
if skippedMissingShips > 0 {
logger.LogEvent("GameData", "Updating", fmt.Sprintf("skipped %d pool mappings because ship templates were missing (region=%s)", skippedMissingShips, region), logger.LOG_LEVEL_WARN)
}
return nil
}

Expand Down Expand Up @@ -285,23 +291,42 @@ func importBuildTimesSQLC(ctx context.Context, region string, q *gen.Queries) er
if err := decoder.Decode(&buildTimes); err != nil {
return err
}
skippedMissingShips, err := applyBuildTimes(buildTimes, func(templateID int64, buildTime int64) (int64, error) {
tag, err := q.SetShipBuildTime(ctx, gen.SetShipBuildTimeParams{
TemplateID: templateID,
BuildTime: buildTime,
})
if err != nil {
return 0, err
}
return tag.RowsAffected(), nil
})
if err != nil {
return err
}
if skippedMissingShips > 0 {
logger.LogEvent("GameData", "Updating", fmt.Sprintf("skipped %d build times because ship templates were missing (region=%s)", skippedMissingShips, region), logger.LOG_LEVEL_WARN)
}
return nil
}

func applyBuildTimes(buildTimes map[string]uint32, setBuildTime func(templateID int64, buildTime int64) (int64, error)) (int, error) {
skippedMissingShips := 0
for id, timeValue := range buildTimes {
parsed, err := strconv.ParseInt(id, 10, 64)
if err != nil {
return err
return 0, err
}
tag, err := q.SetShipBuildTime(ctx, gen.SetShipBuildTimeParams{
TemplateID: parsed,
BuildTime: int64(timeValue),
})
rowsAffected, err := setBuildTime(parsed, int64(timeValue))
if err != nil {
return err
return 0, err
}
if tag.RowsAffected() == 0 {
return fmt.Errorf("ship not found for template_id=%s", id)
if rowsAffected == 0 {
skippedMissingShips++
logger.LogEvent("GameData", "Updating", fmt.Sprintf("skipping build time for missing ship template_id=%s", id), logger.LOG_LEVEL_WARN)
}
}
return nil
return skippedMissingShips, nil
}

func importShopOffersSQLC(ctx context.Context, region string, q *gen.Queries) error {
Expand Down
28 changes: 28 additions & 0 deletions internal/misc/update_data_sqlc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package misc

import "testing"

func TestApplyBuildTimesSkipsMissingShipTemplate(t *testing.T) {
buildTimes := map[string]uint32{"10400031": 16200}

called := false
skipped, err := applyBuildTimes(buildTimes, func(templateID int64, buildTime int64) (int64, error) {
called = true
if templateID != 10400031 {
t.Fatalf("expected template id 10400031, got %d", templateID)
}
if buildTime != 16200 {
t.Fatalf("expected build time 16200, got %d", buildTime)
}
return 0, nil
})
if err != nil {
t.Fatalf("expected no error, got %v", err)
}
if !called {
t.Fatalf("expected setBuildTime callback to be called")
}
if skipped != 1 {
t.Fatalf("expected one skipped template, got %d", skipped)
}
}