Skip to content

Commit e210244

Browse files
authored
Enhance getGraphBlobEntries filter (#1115)
Co-authored-by: Johannes Terblanche <Affie@users.noreply.github.com>
1 parent 2f2385b commit e210244

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

src/DataBlobs/services/BlobEntry.jl

+9-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function getBlobEntry(var::VariableDFG, key::Symbol)
8484
return var.blobEntries[findfirst(x -> x.label == key, var.blobEntries)]
8585
end
8686

87+
#TODO maybe rename to getBlobEntryFirst
8788
function getBlobEntry(var::AbstractDFGVariable, blobId::UUID)
8889
for (k, v) in var.dataDict
8990
if blobId in [v.originId, v.blobId]
@@ -121,7 +122,14 @@ function getBlobEntryFirst(var::VariableDFG, key::Regex)
121122
end
122123

123124
function getBlobEntryFirst(dfg::AbstractDFG, label::Symbol, key::Regex)
124-
return getBlobEntryFirst(getVariable(dfg, label), key)
125+
els = listBlobEntries(dfg, label)
126+
firstIdx = findfirst(contains(key), string.(els))
127+
isnothing(firstIdx) && throw(
128+
KeyError(
129+
"No blobEntry with label matching regex $(key) found in variable $(label)",
130+
),
131+
)
132+
return getBlobEntry(dfg, label, els[firstIdx])
125133
end
126134

127135
# TODO Consider autogenerating all methods of the form:

src/DataBlobs/services/BlobStores.jl

+13-2
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,17 @@ end
8383
##==============================================================================
8484

8585
function getBlob(dfg::AbstractDFG, entry::BlobEntry)
86-
# cannot use entry.blobstore because the blob can be in any one of the blobstores
8786
stores = getBlobStores(dfg)
88-
for (k, store) in stores
87+
storekeys = collect(keys(stores))
88+
# first check the saved blobstore and then fall back to the rest
89+
fidx = findfirst(==(entry.blobstore), storekeys)
90+
if !isnothing(fidx)
91+
skey = storekeys[fidx]
92+
popat!(storekeys, fidx)
93+
pushfirst!(storekeys, skey)
94+
end
95+
for k in storekeys
96+
store = stores[k]
8997
try
9098
blob = getBlob(store, entry)
9199
return blob
@@ -181,6 +189,9 @@ struct FolderStore{T} <: AbstractBlobStore{T}
181189
folder::String
182190
end
183191

192+
#TODO added in v0.25 to avoid a breaking change in deserialization old DFGs, remove.
193+
StructTypes.StructType(::Type{<:FolderStore}) = StructTypes.OrderedStruct()
194+
184195
function FolderStore(foldername::String; label = :default_folder_store, createfolder = true)
185196
if createfolder && !isdir(foldername)
186197
@info "Folder '$foldername' doesn't exist - creating."

src/GraphsDFG/services/GraphsDFG.jl

+10-2
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,17 @@ function getGraphBlobEntry(fg::GraphsDFG, label::Symbol)
527527
return fg.graphBlobEntries[label]
528528
end
529529

530-
function getGraphBlobEntries(fg::GraphsDFG, startwith::Union{Nothing, String} = nothing)
530+
function getGraphBlobEntries(
531+
fg::GraphsDFG,
532+
filt::Union{Nothing, String, Base.Fix2} = nothing,
533+
)
531534
entries = collect(values(fg.graphBlobEntries))
532-
!isnothing(startwith) && filter!(e -> startswith(string(e.label), startwith), entries)
535+
if !isnothing(filt) && isa(filt, String)
536+
@warn "String filter is deprecated, use startswith(filt_string) instead"
537+
filter!(e -> startswith(string(e.label), filt), entries)
538+
elseif !isnothing(filt)
539+
filter!(e -> filt(string(e.label)), entries)
540+
end
533541
return entries
534542
end
535543

0 commit comments

Comments
 (0)