Skip to content

Commit cecb4ca

Browse files
authored
Cleanup, fixes and better listNeighborhood (#1206)
* Cleanup, fixes and better listNeighborhood * Apply suggestions from code review
1 parent b9a43ec commit cecb4ca

File tree

18 files changed

+377
-327
lines changed

18 files changed

+377
-327
lines changed

src/Common.jl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,30 @@ function solveGraphParametric! end
182182

183183
# delta timestamps
184184
calcDeltatime(from::Nanosecond, to::Nanosecond) = Dates.value(to - from) / 10^9
185+
186+
function calcDeltatime_ns(from::TimeDateZone, to::TimeDateZone)
187+
# TODO (-)(x::TimeDateZone, y::TimeDateZone) was very slow so manually calculated here
188+
# return Dates.value(convert(Nanosecond, to - from)) / 10^9
189+
# calculate the "fast part" (microsecond) of the delta timestamp in nanoseconds
190+
fast_to = convert(Nanosecond, Microsecond(to)) + Nanosecond(to)
191+
fast_from = convert(Nanosecond, Microsecond(from)) + Nanosecond(from)
192+
delta_fast = fast_to - fast_from
193+
# calculate the "slow part" (zoned date time) of the delta timestamp in nanoseconds
194+
delta_zoned = convert(Nanosecond, ZonedDateTime(to) - ZonedDateTime(from))
195+
return delta_zoned + delta_fast
196+
end
197+
185198
function calcDeltatime(from::TimeDateZone, to::TimeDateZone)
186-
return Dates.value(convert(Nanosecond, to - from)) / 10^9
199+
# TODO (-)(x::TimeDateZone, y::TimeDateZone) was very slow so manually calculated here
200+
# return Dates.value(convert(Nanosecond, to - from)) / 10^9
201+
return Dates.value(calcDeltatime_ns(from, to)) / 10^9
187202
end
203+
188204
calcDeltatime(from_node, to_node) = calcDeltatime(from_node.timestamp, to_node.timestamp)
189205

190206
Timestamp(args...) = TimeDateZone(args...)
191207
Timestamp(t::Nanosecond, zone = tz"UTC") = Timestamp(Val(:unix), t, zone)
208+
Timestamp(t::Microsecond, zone = tz"UTC") = Timestamp(Val(:unix), Nanosecond(t), zone)
192209
function Timestamp(epoch::Val{:unix}, t::Nanosecond, zone = tz"UTC")
193210
return TimeDateZone(TimeDate(1970) + t, zone)
194211
end

src/DataBlobs/entities/BlobEntry.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ function Blobentry(
7272
size::Int64 = entry.size,
7373
origin::String = entry.origin,
7474
description::String = entry.description,
75-
mimetype::String = entry.mimetype,
75+
mimetype::MIME = entry.mimetype,
7676
metadata::JSONText = entry.metadata,
77-
timestamp::ZonedDateTime = entry.timestamp,
77+
timestamp::TimeDateZone = entry.timestamp,
7878
version = entry.version,
7979
)
8080
return Blobentry(;

src/DataBlobs/services/BlobStores.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ end
124124
FolderStore(label::Symbol, folder::String) = FolderStore{Vector{UInt8}}(label, folder)
125125

126126
function FolderStore(foldername::String; label::Symbol = :default, createfolder = true)
127-
storepath = joinpath(foldername, string(label))
127+
storepath = expanduser(joinpath(foldername, string(label)))
128128
if createfolder && !isdir(storepath)
129129
@info "Folder '$storepath' doesn't exist - creating."
130130
# create new folder
@@ -134,11 +134,11 @@ function FolderStore(foldername::String; label::Symbol = :default, createfolder
134134
end
135135

136136
function blobfilename(store::FolderStore, blobid::UUID)
137-
return joinpath(store.folder, string(store.label), string(blobid))
137+
return expanduser(joinpath(store.folder, string(store.label), string(blobid)))
138138
end
139139

140140
function getBlob(store::FolderStore{T}, blobid::UUID) where {T}
141-
blobfilename = joinpath(store.folder, string(store.label), string(blobid))
141+
blobfilename = expanduser(joinpath(store.folder, string(store.label), string(blobid)))
142142
tombstonefile = blobfilename * ".deleted"
143143
if isfile(tombstonefile)
144144
throw(IdNotFoundError("Blob (deleted)", blobid))
@@ -152,7 +152,7 @@ function getBlob(store::FolderStore{T}, blobid::UUID) where {T}
152152
end
153153

154154
function addBlob!(store::FolderStore{T}, blobid::UUID, data::T) where {T}
155-
blobfilename = joinpath(store.folder, string(store.label), string(blobid))
155+
blobfilename = expanduser(joinpath(store.folder, string(store.label), string(blobid)))
156156
if isfile(blobfilename)
157157
throw(IdExistsError("Blob", blobid))
158158
else
@@ -165,7 +165,7 @@ end
165165

166166
function deleteBlob!(store::FolderStore{T}, blobid::UUID) where {T}
167167
# Tombstone pattern: instead of deleting the file, create a tombstone marker file
168-
blobfilename = joinpath(store.folder, string(store.label), string(blobid))
168+
blobfilename = expanduser(joinpath(store.folder, string(store.label), string(blobid)))
169169
tombstonefile = blobfilename * ".deleted"
170170
if isfile(blobfilename)
171171
# Remove the actual blob file
@@ -185,14 +185,14 @@ function deleteBlob!(store::FolderStore{T}, blobid::UUID) where {T}
185185
end
186186

187187
function hasBlob(store::FolderStore, blobid::UUID)
188-
blobfilename = joinpath(store.folder, string(store.label), string(blobid))
188+
blobfilename = expanduser(joinpath(store.folder, string(store.label), string(blobid)))
189189
return isfile(blobfilename)
190190
end
191191

192192
hasBlob(store::FolderStore, entry::Blobentry) = hasBlob(store, entry.blobid)
193193

194194
function listBlobs(store::FolderStore)
195-
folder = joinpath(store.folder, string(store.label))
195+
folder = expanduser(joinpath(store.folder, string(store.label)))
196196
# Parse folder to only include UUIDs automatically excluding tombstone files this way.
197197
blobids = UUID[]
198198
for filename in readdir(folder)
@@ -249,11 +249,11 @@ listBlobs(store::InMemoryBlobstore) = collect(keys(store.blobs))
249249
##==============================================================================
250250
## LinkStore Link blobid to a existing local folder
251251
##==============================================================================
252-
253-
struct LinkStore <: AbstractBlobstore{String}
252+
#TODO consider using a deterministic blobid (uuid5) with ns stored in the csv?
253+
@tags struct LinkStore <: AbstractBlobstore{String}
254254
label::Symbol
255255
csvfile::String
256-
cache::Dict{UUID, String}
256+
cache::Dict{UUID, String} & (json = (ignore = true,),)
257257

258258
function LinkStore(label, csvfile)
259259
if !isfile(csvfile)

src/Deprecated.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,10 @@ end
362362
args...;
363363
kwargs...,
364364
)
365+
366+
function getVariable(dfg::AbstractDFG, label::Symbol, stateLabel::Symbol)
367+
Base.depwarn("getVariable with stateLabel is deprecated", :getVariable)
368+
#TODO DFG v1.x will maybe use getVariable(dfg, label; stateLabelFilter) instead.
369+
return getVariable(dfg, label)
370+
# return getVariable(dfg, label; stateLabelFilter = ==(stateLabel))
371+
end

0 commit comments

Comments
 (0)