Fixed twitch history query

This commit is contained in:
Asaf Gartner 2022-10-13 19:55:51 +03:00
parent cf809a3cdc
commit 56929e6e44
1 changed files with 22 additions and 6 deletions

View File

@ -1005,10 +1005,25 @@ func findHistoryVOD(ctx context.Context, dbConn db.ConnOrTx, history *models.Twi
UPDATE twitch_stream_history UPDATE twitch_stream_history
SET SET
vod_gone = $2, vod_gone = $2,
last_verified_vod = $3
WHERE stream_id = $1 WHERE stream_id = $1
`, `,
history.StreamID, history.StreamID,
history.VODGone, history.VODGone,
time.Now(),
)
if err != nil {
return oops.New(err, "failed to update stream history")
}
} else {
_, err = dbConn.Exec(ctx, `
UPDATE twitch_stream_history
SET
last_verified_vod = $2
WHERE stream_id = $1
`,
history.StreamID,
time.Now(),
) )
if err != nil { if err != nil {
return oops.New(err, "failed to update stream history") return oops.New(err, "failed to update stream history")
@ -1025,21 +1040,22 @@ func findMissingVODs(ctx context.Context, dbConn db.ConnOrTx) error {
FROM twitch_stream_history FROM twitch_stream_history
WHERE WHERE
vod_gone = FALSE AND vod_gone = FALSE AND
vod_id = '' ended_at = $1
ORDER BY last_verified_vod ASC
LIMIT 100
`, `,
time.Time{},
) )
if err != nil { if err != nil {
return oops.New(err, "failed to fetch stream history for vod updates") return oops.New(err, "failed to fetch stream history for vod updates")
} }
for _, history := range histories { for _, history := range histories {
if history.EndedAt.IsZero() {
err = findHistoryVOD(ctx, dbConn, history) err = findHistoryVOD(ctx, dbConn, history)
if err != nil { if err != nil {
return err return err
} }
} }
}
return nil return nil
} }