diff --git a/src/DataBlobs/services/BlobEntry.jl b/src/DataBlobs/services/BlobEntry.jl index 31d37a23..b92a6f49 100644 --- a/src/DataBlobs/services/BlobEntry.jl +++ b/src/DataBlobs/services/BlobEntry.jl @@ -84,6 +84,7 @@ function getBlobEntry(var::VariableDFG, key::Symbol) return var.blobEntries[findfirst(x -> x.label == key, var.blobEntries)] end +#TODO maybe rename to getBlobEntryFirst function getBlobEntry(var::AbstractDFGVariable, blobId::UUID) for (k, v) in var.dataDict if blobId in [v.originId, v.blobId] @@ -121,7 +122,14 @@ function getBlobEntryFirst(var::VariableDFG, key::Regex) end function getBlobEntryFirst(dfg::AbstractDFG, label::Symbol, key::Regex) - return getBlobEntryFirst(getVariable(dfg, label), key) + els = listBlobEntries(dfg, label) + firstIdx = findfirst(contains(key), string.(els)) + isnothing(firstIdx) && throw( + KeyError( + "No blobEntry with label matching regex $(key) found in variable $(label)", + ), + ) + return getBlobEntry(dfg, label, els[firstIdx]) end # TODO Consider autogenerating all methods of the form: diff --git a/src/DataBlobs/services/BlobStores.jl b/src/DataBlobs/services/BlobStores.jl index 1ac5580c..7ca2469c 100644 --- a/src/DataBlobs/services/BlobStores.jl +++ b/src/DataBlobs/services/BlobStores.jl @@ -83,9 +83,17 @@ end ##============================================================================== function getBlob(dfg::AbstractDFG, entry::BlobEntry) - # cannot use entry.blobstore because the blob can be in any one of the blobstores stores = getBlobStores(dfg) - for (k, store) in stores + storekeys = collect(keys(stores)) + # first check the saved blobstore and then fall back to the rest + fidx = findfirst(==(entry.blobstore), storekeys) + if !isnothing(fidx) + skey = storekeys[fidx] + popat!(storekeys, fidx) + pushfirst!(storekeys, skey) + end + for k in storekeys + store = stores[k] try blob = getBlob(store, entry) return blob @@ -181,6 +189,9 @@ struct FolderStore{T} <: AbstractBlobStore{T} folder::String end +#TODO added in v0.25 to avoid a breaking change in deserialization old DFGs, remove. +StructTypes.StructType(::Type{<:FolderStore}) = StructTypes.OrderedStruct() + function FolderStore(foldername::String; label = :default_folder_store, createfolder = true) if createfolder && !isdir(foldername) @info "Folder '$foldername' doesn't exist - creating." diff --git a/src/GraphsDFG/services/GraphsDFG.jl b/src/GraphsDFG/services/GraphsDFG.jl index 53c23908..f238b97c 100644 --- a/src/GraphsDFG/services/GraphsDFG.jl +++ b/src/GraphsDFG/services/GraphsDFG.jl @@ -527,9 +527,17 @@ function getGraphBlobEntry(fg::GraphsDFG, label::Symbol) return fg.graphBlobEntries[label] end -function getGraphBlobEntries(fg::GraphsDFG, startwith::Union{Nothing, String} = nothing) +function getGraphBlobEntries( + fg::GraphsDFG, + filt::Union{Nothing, String, Base.Fix2} = nothing, +) entries = collect(values(fg.graphBlobEntries)) - !isnothing(startwith) && filter!(e -> startswith(string(e.label), startwith), entries) + if !isnothing(filt) && isa(filt, String) + @warn "String filter is deprecated, use startswith(filt_string) instead" + filter!(e -> startswith(string(e.label), filt), entries) + elseif !isnothing(filt) + filter!(e -> filt(string(e.label)), entries) + end return entries end