3
3
$(SIGNATURES)
4
4
Create a new CloudGraphs-based DFG factor graph using a Neo4j.Connection.
5
5
"""
6
- function CloudGraphsDFG {T} (neo4jConnection:: Neo4j.Connection , userId:: String , robotId:: String , sessionId:: String , encodePackedTypeFunc, getPackedTypeFunc, decodePackedTypeFunc, rebuildFactorMetadata!; description:: String = " CloudGraphs DFG" , solverParams:: T = NoSolverParams (), useCache:: Bool = false ) where T <: AbstractParams
6
+ function CloudGraphsDFG {T} (neo4jConnection:: Neo4j.Connection ,
7
+ userId:: String ,
8
+ robotId:: String ,
9
+ sessionId:: String ,
10
+ encodePackedTypeFunc,
11
+ getPackedTypeFunc,
12
+ decodePackedTypeFunc,
13
+ rebuildFactorMetadata!;
14
+ description:: String = " CloudGraphs DFG" ,
15
+ solverParams:: T = NoSolverParams ()) where T <: AbstractParams
7
16
graph = Neo4j. getgraph (neo4jConnection)
8
17
neo4jInstance = Neo4jInstance (neo4jConnection, graph)
9
- return CloudGraphsDFG {T} (neo4jInstance, description, userId, robotId, sessionId, encodePackedTypeFunc, getPackedTypeFunc, decodePackedTypeFunc, rebuildFactorMetadata!, Dict {Symbol, Int64} (), Dict { Symbol, DFGVariable} (), Dict {Symbol, DFGFactor} (), Symbol [], solverParams, useCache )
18
+ return CloudGraphsDFG {T} (neo4jInstance, description, userId, robotId, sessionId, encodePackedTypeFunc, getPackedTypeFunc, decodePackedTypeFunc, rebuildFactorMetadata!, Dict {Symbol, Int64} (), Symbol[], solverParams)
10
19
end
11
20
"""
12
21
$(SIGNATURES)
13
22
Create a new CloudGraphs-based DFG factor graph by specifying the Neo4j connection information.
14
23
"""
15
- function CloudGraphsDFG {T} (host:: String , port:: Int , dbUser:: String , dbPassword:: String , userId:: String , robotId:: String , sessionId:: String , encodePackedTypeFunc, getPackedTypeFunc, decodePackedTypeFunc, rebuildFactorMetadata!; description:: String = " CloudGraphs DFG" , solverParams:: T = NoSolverParams (), useCache:: Bool = false ) where T <: AbstractParams
24
+ function CloudGraphsDFG {T} (host:: String ,
25
+ port:: Int ,
26
+ dbUser:: String ,
27
+ dbPassword:: String ,
28
+ userId:: String ,
29
+ robotId:: String ,
30
+ sessionId:: String ,
31
+ encodePackedTypeFunc,
32
+ getPackedTypeFunc,
33
+ decodePackedTypeFunc,
34
+ rebuildFactorMetadata!;
35
+ description:: String = " CloudGraphs DFG" ,
36
+ solverParams:: T = NoSolverParams ()) where T <: AbstractParams
16
37
neo4jConnection = Neo4j. Connection (host, port= port, user= dbUser, password= dbPassword);
17
- return CloudGraphsDFG {T} (neo4jConnection, userId, robotId, sessionId, encodePackedTypeFunc, getPackedTypeFunc, decodePackedTypeFunc, rebuildFactorMetadata!, description= description, solverParams= solverParams, useCache = useCache )
38
+ return CloudGraphsDFG {T} (neo4jConnection, userId, robotId, sessionId, encodePackedTypeFunc, getPackedTypeFunc, decodePackedTypeFunc, rebuildFactorMetadata!, description= description, solverParams= solverParams)
18
39
end
19
40
20
41
"""
@@ -30,7 +51,7 @@ function _getDuplicatedEmptyDFG(dfg::CloudGraphsDFG)::CloudGraphsDFG
30
51
length (_getLabelsFromCyphonQuery (dfg. neo4jInstance, " (node:$(dfg. userId) :$(dfg. robotId) :$(sessionId) )" )) == 0 && break
31
52
end
32
53
@debug " Unique+empty copy session name: $sessionId "
33
- return CloudGraphsDFG {typeof(dfg.solverParams)} (dfg. neo4jInstance. connection, dfg. userId, dfg. robotId, sessionId, dfg. encodePackedTypeFunc, dfg. getPackedTypeFunc, dfg. decodePackedTypeFunc, dfg. rebuildFactorMetadata!, solverParams= deepcopy (dfg. solverParams), description= " (Copy of) $(dfg. description) " , useCache = dfg . useCache )
54
+ return CloudGraphsDFG {typeof(dfg.solverParams)} (dfg. neo4jInstance. connection, dfg. userId, dfg. robotId, sessionId, dfg. encodePackedTypeFunc, dfg. getPackedTypeFunc, dfg. decodePackedTypeFunc, dfg. rebuildFactorMetadata!, solverParams= deepcopy (dfg. solverParams), description= " (Copy of) $(dfg. description) " )
34
55
end
35
56
36
57
# Accessors
@@ -49,8 +70,6 @@ function getSerializationModule(dfg::CloudGraphsDFG)::Module where G <: Abstract
49
70
end
50
71
51
72
function exists (dfg:: CloudGraphsDFG , nId:: Symbol )
52
- # If in the dictionary, then shortcut return true
53
- dfg. useCache && haskey (dfg. labelDict, nId) && return true
54
73
# Otherwise try get it
55
74
nodeId = _tryGetNeoNodeIdFromNodeLabel (dfg. neo4jInstance, dfg. userId, dfg. robotId, dfg. sessionId, nId)
56
75
if nodeId != nothing
@@ -80,12 +99,10 @@ function addVariable!(dfg::CloudGraphsDFG, variable::DFGVariable)::DFGVariable
80
99
Neo4j. updatenodelabels (neo4jNode, union ([string (variable. label), " VARIABLE" , dfg. userId, dfg. robotId, dfg. sessionId], variable. tags))
81
100
82
101
# Make sure that if there exists a SESSION sentinel that it is attached.
83
- # TODO : Optimize this.
84
102
_bindSessionNodeToInitialVariable (dfg. neo4jInstance, dfg. userId, dfg. robotId, dfg. sessionId, string (variable. label))
85
103
86
104
# Update our internal dictionaries.
87
105
push! (dfg. labelDict, variable. label=> variable. _internalId)
88
- push! (dfg. variableCache, variable. label=> variable)
89
106
# Track insertion
90
107
push! (dfg. addHistory, variable. label)
91
108
@@ -120,7 +137,6 @@ function addFactor!(dfg::CloudGraphsDFG, variables::Vector{<:DFGVariable}, facto
120
137
121
138
# Graphs.add_vertex!(dfg.g, v)
122
139
push! (dfg. labelDict, factor. label=> factor. _internalId)
123
- push! (dfg. factorCache, factor. label=> factor)
124
140
# Track insertion only for variables
125
141
# push!(dfg.addHistory, factor.label
126
142
@@ -137,9 +153,6 @@ function getVariable(dfg::CloudGraphsDFG, variableId::Int64)::DFGVariable
137
153
variable = unpackVariable (dfg, props)
138
154
variable. _internalId = variableId
139
155
140
- # Add to cache
141
- push! (dfg. variableCache, variable. label=> variable)
142
-
143
156
return variable
144
157
end
145
158
@@ -148,8 +161,6 @@ function getVariable(dfg::CloudGraphsDFG, label::Union{Symbol, String})::DFGVari
148
161
if typeof (label) == String
149
162
label = Symbol (label)
150
163
end
151
- dfg. useCache && haskey (dfg. variableCache, label) && return dfg. variableCache[label]
152
- # Else try get it
153
164
nodeId = _tryGetNeoNodeIdFromNodeLabel (dfg. neo4jInstance, dfg. userId, dfg. robotId, dfg. sessionId, label)
154
165
if nodeId == nothing
155
166
error (" Unable to retrieve the ID for variable '$label '. Please check your connection to the database and that the variable exists." )
160
171
161
172
function getFactor (dfg:: CloudGraphsDFG , factorId:: Int64 ):: DFGFactor
162
173
props = getnodeproperties (dfg. neo4jInstance. graph, factorId)
163
- factor = unpackFactor (dfg, props, getSerializationModule (dfg) )
174
+ factor = unpackFactor (dfg, props)
164
175
factor. _internalId = factorId
165
176
166
177
# Lastly, rebuild the metadata
@@ -169,18 +180,13 @@ function getFactor(dfg::CloudGraphsDFG, factorId::Int64)::DFGFactor
169
180
# ... TODO : refactor if changed: https://github.com/JuliaRobotics/IncrementalInference.jl/issues/350
170
181
getSolverData (factor). fncargvID = factor. _variableOrderSymbols
171
182
172
- # Add to cache
173
- push! (dfg. factorCache, factor. label=> factor)
174
-
175
183
return factor
176
184
end
177
185
178
186
function getFactor (dfg:: CloudGraphsDFG , label:: Union{Symbol, String} ):: DFGFactor
179
187
if typeof (label) == String
180
188
label = Symbol (label)
181
189
end
182
- dfg. useCache && haskey (dfg. factorCache, label) && return dfg. factorCache[label]
183
- # Else try get it
184
190
nodeId = _tryGetNeoNodeIdFromNodeLabel (dfg. neo4jInstance, dfg. userId, dfg. robotId, dfg. sessionId, label)
185
191
if nodeId == nothing
186
192
error (" Unable to retrieve the ID for factor '$label '. Please check your connection to the database and that the factor exists." )
@@ -216,7 +222,7 @@ function mergeUpdateVariableSolverData!(dfg::CloudGraphsDFG, sourceVariable::DFG
216
222
Neo4j. setnodeproperty (dfg. neo4jInstance. graph, var. _internalId, " ppeDict" ,
217
223
JSON2. write (newEsts))
218
224
Neo4j. setnodeproperty (dfg. neo4jInstance. graph, var. _internalId, " solverDataDict" ,
219
- JSON2. write (Dict (keys (newSolveData) .=> map (vnd -> pack (dfg, vnd), values (newSolveData)))))
225
+ JSON2. write (Dict (keys (newSolveData) .=> map (vnd -> packVariableNodeData (dfg, vnd), values (newSolveData)))))
220
226
return sourceVariable
221
227
end
222
228
@@ -272,13 +278,7 @@ function updateFactor!(dfg::CloudGraphsDFG, variableIds::Vector{Symbol}, factor:
272
278
end
273
279
274
280
function deleteVariable! (dfg:: CloudGraphsDFG , label:: Symbol ):: DFGVariable
275
- variable = nothing
276
- if dfg. useCache && haskey (dfg. variableCache, label)
277
- variable = dfg. variableCache[label]
278
- else
279
- # Else try get it
280
- variable = getVariable (dfg, label)
281
- end
281
+ variable = getVariable (dfg, label)
282
282
if variable == nothing
283
283
error (" Unable to retrieve the ID for variable '$label '. Please check your connection to the database and that the variable exists." )
284
284
end
@@ -288,7 +288,6 @@ function deleteVariable!(dfg::CloudGraphsDFG, label::Symbol)::DFGVariable
288
288
289
289
# Clearing history
290
290
dfg. addHistory = symdiff (dfg. addHistory, [label])
291
- haskey (dfg. variableCache, label) && delete! (dfg. variableCache, label)
292
291
haskey (dfg. labelDict, label) && delete! (dfg. labelDict, label)
293
292
return variable
294
293
end
297
296
deleteVariable! (dfg:: CloudGraphsDFG , variable:: DFGVariable ):: DFGVariable = deleteVariable! (dfg, variable. label)
298
297
299
298
function deleteFactor! (dfg:: CloudGraphsDFG , label:: Symbol ):: DFGFactor
300
- factor = nothing
301
- if dfg. useCache && haskey (dfg. factoreCache, label)
302
- factor = dfg. factorCache[label]
303
- else
304
- # Else try get it
305
- factor = getFactor (dfg, label)
306
- end
299
+ factor = getFactor (dfg, label)
307
300
if factor == nothing
308
301
error (" Unable to retrieve the ID for factor '$label '. Please check your connection to the database and that the factor exists." )
309
302
end
@@ -313,7 +306,6 @@ function deleteFactor!(dfg::CloudGraphsDFG, label::Symbol)::DFGFactor
313
306
314
307
# Clearing history
315
308
dfg. addHistory = symdiff (dfg. addHistory, [label])
316
- haskey (dfg. factorCache, label) && delete! (dfg. factorCache, label)
317
309
haskey (dfg. labelDict, label) && delete! (dfg. labelDict, label)
318
310
return factor
319
311
end
0 commit comments