BHoM_Adapter: refactoring-refactor the ReplaceInMemory #106
Labels
severity:medium
Slows progress, but workaround is possible
type:compliance
Non-conforming to code guidelines
Milestone
The ReplaceInMemory has an counterintuitive structure that needs to be refactored.
Issue 1 - Fix missed VennDiagram bug
Fix #88.
Issue 2 - structure of ReplaceInMemory and call to
Create()
Counter-intuitively, the Create method will have to take care not only to create (export) these objects, but it is assumed also to be deleting any object existing in the model.
To distinguish this case, there is a boolean argument
replaceAll
to be set to true when calling Create(), which is not good.Step by step explanation:
replaceAll
was added to the Create method. When activated, it is assumed that the Create will be deleting objects. This parameter is used exclusively for this purpose.Replace
method hard-codesreplaceAll
to true (here renamed tooverwriteObjects
):BHoM_Adapter/BHoM_Adapter/CRUD/Replace.cs
Lines 67 to 71 in 49d63e8
So Create will get called with
ReplaceAll
set to true when ReplaceInMemory was used:BHoM_Adapter/BHoM_Adapter/CRUD/Replace.cs
Line 84 in 49d63e8
Which is definitely not nice.
I have raised an issue to collection all related toolkit issues: #114
Proposed solution
The
replaceAll
parameter should be removed by the Create method signature.Any deletion should be preformed using the Delete method.
Issue 3 - usage of ReplaceInMemory
ReplaceInMemory involves the use of two
AdapterConfig
properties:ProcessInMemory
needs to be true in order for ReplaceInMemory to be called.MergeWithComparer
to have the ReplaceInMemory using the comparers to do the merge. If this is set to false, the ReplaceInMemory becomes a sort of "CreateOnly" method (except it does not Create the objects with the same tag currently Pushed, a rather cryptic behaviour).Now, consider that in order to use ReplaceInMemory as intended, you need to:
ProcessInMemory
to true, ANDLet's find out about the usage of the ReplaceInMemory then:
➡️ The FileAdapter is the only one that uses ReplaceInMemory as intended.
Another 4 adapters are specifying
ProcessInMemory
as true, but since they are not implementing Create(), they are not using this ReplaceInMemory as intended. These are:Unreal_Toolkit; Filing_Toolkit; Civil_Toolkit; GitHub_Toolkit.
➡️ For those, the theory is that people have been using ReplaceInMemory as a sort of
CreateOnly
method, disregarding tags.➡️
AdapterConfig.MergeWithComparer
is never used.Proposed solution
AdapterConfig.MergeWithComparer
. ReplaceInMemory should always use comparers, like ReplaceThroughAPI.CreateOnly
method instead of ReplaceInMemory.replaceAll
is always set to false. Some of the code needs to be cleaned.The text was updated successfully, but these errors were encountered: