Skip to content
Snippets Groups Projects
Commit 55ddefb0 authored by Travis Ralston's avatar Travis Ralston
Browse files

Improve some database handling around downloads

parent 063d70cf
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
* Fixed a download inefficiency where remote downloads could use extra bandwidth.
* Fixed a problem where secondary imports can never finish.
* Fixed imports not handling duplicate media IDs.
* Fixed some database connection errors not being handled correctly.
## [1.2.4] - March 5th, 2021
......
......@@ -182,6 +182,10 @@ func FindMinimalMediaRecord(origin string, mediaId string, downloadRemote bool,
ctx.Log.Warn("Media not found")
return nil, common.ErrMediaNotFound
}
} else {
// We don't even want to attempt a download - something very wrong happened
ctx.Log.Error("Database error trying to get media:", err.Error())
return nil, err
}
if !downloadRemote {
......@@ -263,6 +267,10 @@ func FindMediaRecord(origin string, mediaId string, downloadRemote bool, ctx rco
ctx.Log.Warn("Media not found")
return nil, common.ErrMediaNotFound
}
} else {
// We don't even want to attempt a download - something very wrong happened
ctx.Log.Error("Database error trying to get media:", err.Error())
return nil, err
}
if !downloadRemote {
......
......@@ -267,6 +267,16 @@ func StoreDirect(f *AlreadyUploadedFile, contents io.ReadCloser, expectedSize in
return nil, common.ErrMediaQuarantined
}
// Double check that we're not about to try and store a record we know about
for _, knownRecord := range records {
if knownRecord.Origin == origin && knownRecord.MediaId == mediaId {
ctx.Log.Info("Duplicate media record found - returning unaltered record")
ds.DeleteObject(info.Location) // delete temp object
trackUploadAsLastAccess(ctx, knownRecord)
return knownRecord, nil
}
}
media := record
media.Origin = origin
media.MediaId = mediaId
......
......@@ -113,6 +113,7 @@ func PickDatastore(forKind string, ctx rcontext.RequestContext) (*DatastoreRef,
ds, err := mediaStore.GetDatastoreByUri(GetUriForDatastore(dsConf))
if err != nil {
ctx.Log.Error("Error getting datastore: ", err.Error())
continue
}
......@@ -121,6 +122,7 @@ func PickDatastore(forKind string, ctx rcontext.RequestContext) (*DatastoreRef,
if len(confDatastores) > 1 {
size, err = estimatedDatastoreSize(ds, ctx)
if err != nil {
ctx.Log.Error("Error estimating datastore size for ", ds.DatastoreId, ": ", err.Error())
continue
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment