Skip to content

Commit

Permalink
Fix #5128 - Properly remove old components/measures when updating
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed Mar 27, 2024
1 parent f916fc1 commit 0285e41
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
22 changes: 22 additions & 0 deletions src/utilities/bcl/LocalBCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,28 @@ bool LocalBCL::removeMeasure(BCLMeasure& measure) {
return true;
}

size_t LocalBCL::removeOutdatedLocalComponents(const std::string& uid, const std::string& currentVersionId) {
size_t num_removed = 0;
for (auto& component : components()) {
if ((component.uid() == uid) && (component.versionId() != currentVersionId)) {
++num_removed;
removeComponent(component);
}
}
return num_removed;
}

size_t LocalBCL::removeOutdatedLocalMeasures(const std::string& uid, const std::string& currentVersionId) {
size_t num_removed = 0;
for (auto& measure : measures()) {
if ((measure.uid() == uid) && (measure.versionId() != currentVersionId)) {
++num_removed;
removeMeasure(measure);
}
}
return num_removed;
}

std::vector<BCLComponent> LocalBCL::componentAttributeSearch(const std::vector<std::pair<std::string, std::string>>& searchTerms) const {
auto uids = attributeSearch(searchTerms, "component");
if (uids.empty()) {
Expand Down
6 changes: 6 additions & 0 deletions src/utilities/bcl/LocalBCL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ class UTILITIES_API LocalBCL : public BCL
// cppcheck-suppress constParameter
bool removeMeasure(BCLMeasure& measure);

// Removes all components with uid but NOT currentVersionId
size_t removeOutdatedLocalComponents(const std::string& uid, const std::string& currentVersionId);

// Removes all measures with uid but NOT currentVersionId
size_t removeOutdatedLocalMeasures(const std::string& uid, const std::string& currentVersionId);

/// Search for components with attributes matching those in searchTerms
std::vector<BCLComponent> componentAttributeSearch(const std::vector<std::pair<std::string, std::string>>& searchTerms) const;

Expand Down
12 changes: 3 additions & 9 deletions src/utilities/bcl/RemoteBCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,11 @@ void RemoteBCL::updateComponents() {
}

for (const BCLSearchResult& component : m_componentsWithUpdates) {
downloadMeasure(component.uid());
downloadComponent(component.uid());
boost::optional<BCLComponent> newComponent = waitForComponentDownload();

if (newComponent) {
boost::optional<BCLComponent> oldComponent = LocalBCL::instance().getComponent(newComponent->uid());
if (oldComponent && oldComponent->versionId() != newComponent->versionId()) {
LocalBCL::instance().removeComponent(*oldComponent);
}
LocalBCL::instance().removeOutdatedLocalComponents(newComponent->uid(), newComponent->versionId());
}
}
}
Expand All @@ -312,10 +309,7 @@ void RemoteBCL::updateMeasures() {
boost::optional<BCLMeasure> newMeasure = waitForMeasureDownload();

if (newMeasure) {
boost::optional<BCLMeasure> oldMeasure = LocalBCL::instance().getMeasure(newMeasure->uid());
if (oldMeasure && oldMeasure->versionId() != newMeasure->versionId()) {
LocalBCL::instance().removeMeasure(*oldMeasure);
}
LocalBCL::instance().removeOutdatedLocalMeasures(newMeasure->uid(), newMeasure->versionId());
}
}
}
Expand Down

0 comments on commit 0285e41

Please sign in to comment.