Skip to content
Merged
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
20 changes: 14 additions & 6 deletions go/isuports.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,9 @@ func billingReportByCompetition(ctx context.Context, tenantDB dbOrTx, tenantID i
billingMap[pid] = "player"
}

// unlock when it's done to read player_score
fl.Close()

// 大会が終了している場合のみ請求金額が確定するので計算する
var playerCount, visitorCount int64
if comp.FinishedAt.Valid {
Expand Down Expand Up @@ -1075,12 +1078,6 @@ func competitionScoreHandler(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, "invalid CSV headers")
}

// / DELETEしたタイミングで参照が来ると空っぽのランキングになるのでロックする
fl, err := flockByTenantID(v.tenantID)
if err != nil {
return fmt.Errorf("error flockByTenantID: %w", err)
}
defer fl.Close()
var rowNum int64
playerScoreRows := []PlayerScoreRow{}
for {
Expand Down Expand Up @@ -1130,6 +1127,13 @@ func competitionScoreHandler(c echo.Context) error {
})
}

// / DELETEしたタイミングで参照が来ると空っぽのランキングになるのでロックする
fl, err := flockByTenantID(v.tenantID)
if err != nil {
return fmt.Errorf("error flockByTenantID: %w", err)
}
defer fl.Close()

if _, err := tenantDB.ExecContext(
ctx,
"DELETE FROM player_score WHERE tenant_id = ? AND competition_id = ?",
Expand Down Expand Up @@ -1160,6 +1164,8 @@ func competitionScoreHandler(c echo.Context) error {
)
}

fl.Close() // it's done

return c.JSON(http.StatusOK, SuccessResult{
Status: true,
Data: ScoreHandlerResult{Rows: int64(len(playerScoreRows))},
Expand Down Expand Up @@ -1298,6 +1304,8 @@ func playerHandler(c echo.Context) error {
pss = append(pss, ps)
}

fl.Close() // it's done

psds := make([]PlayerScoreDetail, 0, len(pss))
for _, ps := range pss {
comp, err := retrieveCompetition(ctx, tenantDB, ps.CompetitionID)
Expand Down