Skip to content

Commit

Permalink
Enhance getGraphBlobEntries filter (#1115)
Browse files Browse the repository at this point in the history
Co-authored-by: Johannes Terblanche <Affie@users.noreply.github.com>
  • Loading branch information
Affie and Affie authored Feb 3, 2025
1 parent 2f2385b commit e210244
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/DataBlobs/services/BlobEntry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 13 additions & 2 deletions src/DataBlobs/services/BlobStores.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand Down
12 changes: 10 additions & 2 deletions src/GraphsDFG/services/GraphsDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e210244

Please sign in to comment.