From f8aaeff6de2dc5e5321840460d55d79ad1b5ab1a Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 6 Jun 2023 17:01:54 -0400 Subject: [PATCH] fix: rewrite gorm query logic for tus uploads --- tus/tus.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tus/tus.go b/tus/tus.go index e71ce6c..9f8bfaa 100644 --- a/tus/tus.go +++ b/tus/tus.go @@ -94,15 +94,26 @@ func Init() *tusd.Handler { } func tusStartup() { - result := map[int]model.Tus{} - db.Get().Table("tus").Take(&result) - tusQueue := getQueue() store := getStore() - for _, item := range result { + rows, err := db.Get().Model(&model.Tus{}).Rows() + + if err != nil { + logger.Get().Error("failed to query tus uploads", zap.Error(err)) + } + + defer rows.Close() + + for rows.Next() { + var tusUpload model.Tus + err := db.Get().ScanRows(rows, &tusUpload) + if err != nil { + logger.Get().Error("failed to scan tus records", zap.Error(err)) + return + } if err := tusQueue.QueueTask(func(ctx context.Context) error { - upload, err := store.GetUpload(nil, item.UploadID) + upload, err := store.GetUpload(nil, tusUpload.UploadID) if err != nil { logger.Get().Error("failed to query tus upload", zap.Error(err)) return err