Don't update LastFirehoseRev more than once a day

main
Max Ignatenko 2024-04-07 15:06:13 +01:00
parent 581cf8c720
commit 4b40c5919b
1 changed files with 16 additions and 6 deletions

View File

@ -32,6 +32,8 @@ import (
"github.com/uabluerail/indexer/util/resolver" "github.com/uabluerail/indexer/util/resolver"
) )
const lastRevUpdateInterval = 24 * time.Hour
type BadRecord struct { type BadRecord struct {
ID models.ID `gorm:"primarykey"` ID models.ID `gorm:"primarykey"`
CreatedAt time.Time CreatedAt time.Time
@ -430,12 +432,20 @@ func (c *Consumer) processMessage(ctx context.Context, typ string, r io.Reader,
} }
} }
err = c.db.Model(&repo.Repo{}).Where(&repo.Repo{ID: repoInfo.ID}). if repoInfo.FirstCursorSinceReset > 0 && repoInfo.FirstRevSinceReset != "" &&
Updates(&repo.Repo{ repoInfo.LastIndexedRev != "" &&
LastFirehoseRev: payload.Rev, c.remote.FirstCursorSinceReset > 0 &&
}).Error repoInfo.FirstCursorSinceReset >= c.remote.FirstCursorSinceReset &&
if err != nil { repoInfo.FirstRevSinceReset <= repoInfo.LastIndexedRev &&
log.Error().Err(err).Msgf("Failed to update last_firehose_rev for %q: %s", repoInfo.DID, err) time.Since(repoInfo.UpdatedAt) > lastRevUpdateInterval {
err = c.db.Model(&repo.Repo{}).Where(&repo.Repo{ID: repoInfo.ID}).
Updates(&repo.Repo{
LastFirehoseRev: payload.Rev,
}).Error
if err != nil {
log.Error().Err(err).Msgf("Failed to update last_firehose_rev for %q: %s", repoInfo.DID, err)
}
} }
if payload.TooBig { if payload.TooBig {