From 56929e6e4487dadb87629829efd5f9100649d0e0 Mon Sep 17 00:00:00 2001 From: Asaf Gartner Date: Thu, 13 Oct 2022 19:55:51 +0300 Subject: [PATCH] Fixed twitch history query --- src/twitch/twitch.go | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/twitch/twitch.go b/src/twitch/twitch.go index b1589779..bb8d8000 100644 --- a/src/twitch/twitch.go +++ b/src/twitch/twitch.go @@ -1005,10 +1005,25 @@ func findHistoryVOD(ctx context.Context, dbConn db.ConnOrTx, history *models.Twi UPDATE twitch_stream_history SET vod_gone = $2, + last_verified_vod = $3 WHERE stream_id = $1 `, history.StreamID, 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 { return oops.New(err, "failed to update stream history") @@ -1025,19 +1040,20 @@ func findMissingVODs(ctx context.Context, dbConn db.ConnOrTx) error { FROM twitch_stream_history WHERE vod_gone = FALSE AND - vod_id = '' + ended_at = $1 + ORDER BY last_verified_vod ASC + LIMIT 100 `, + time.Time{}, ) if err != nil { return oops.New(err, "failed to fetch stream history for vod updates") } for _, history := range histories { - if history.EndedAt.IsZero() { - err = findHistoryVOD(ctx, dbConn, history) - if err != nil { - return err - } + err = findHistoryVOD(ctx, dbConn, history) + if err != nil { + return err } } return nil