fix: rewrite gorm query logic for tus uploads

This commit is contained in:
Derrick Hammer 2023-06-06 17:01:54 -04:00
parent 99d7b8347a
commit f8aaeff6de
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 16 additions and 5 deletions

View File

@ -94,15 +94,26 @@ func Init() *tusd.Handler {
} }
func tusStartup() { func tusStartup() {
result := map[int]model.Tus{}
db.Get().Table("tus").Take(&result)
tusQueue := getQueue() tusQueue := getQueue()
store := getStore() 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 { 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 { if err != nil {
logger.Get().Error("failed to query tus upload", zap.Error(err)) logger.Get().Error("failed to query tus upload", zap.Error(err))
return err return err