From 24f470a48083b2619fe0042391a20b25155962eb Mon Sep 17 00:00:00 2001 From: RobertBeekman Date: Sun, 25 Feb 2024 15:32:25 +0100 Subject: [PATCH] Storage - Avoid broken LiteDB API --- .../Migrations/Storage/M0024NodeProviders.cs | 25 ++++++++++++------- .../M0025NodeProvidersProfileConfig.cs | 8 ++++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/Artemis.Storage/Migrations/Storage/M0024NodeProviders.cs b/src/Artemis.Storage/Migrations/Storage/M0024NodeProviders.cs index 4d0a4211e..c09c0f1fc 100644 --- a/src/Artemis.Storage/Migrations/Storage/M0024NodeProviders.cs +++ b/src/Artemis.Storage/Migrations/Storage/M0024NodeProviders.cs @@ -10,28 +10,33 @@ public class M0024NodeProviders : IStorageMigration public void Apply(LiteRepository repository) { - List profileCategories = repository.Query().ToList(); - foreach (ProfileCategoryEntity profileCategory in profileCategories) + ILiteCollection categoryCollection = repository.Database.GetCollection("ProfileCategoryEntity"); + List categoriesToUpdate = new(); + foreach (BsonDocument profileCategoryBson in categoryCollection.FindAll()) { - foreach (ProfileConfigurationEntity profileConfigurationEntity in profileCategory.ProfileConfigurations) + BsonArray? profiles = profileCategoryBson["ProfileConfigurations"]?.AsArray; + if (profiles != null) { - profileConfigurationEntity.Version = 1; + foreach (BsonValue profile in profiles) + profile["Version"] = 1; + categoriesToUpdate.Add(profileCategoryBson); } - repository.Update(profileCategory); } + categoryCollection.Update(categoriesToUpdate); ILiteCollection collection = repository.Database.GetCollection("ProfileEntity"); + List profilesToUpdate = new(); foreach (BsonDocument profileBson in collection.FindAll()) { BsonArray? folders = profileBson["Folders"]?.AsArray; BsonArray? layers = profileBson["Layers"]?.AsArray; - + if (folders != null) { foreach (BsonValue folder in folders) MigrateProfileElement(folder.AsDocument); } - + if (layers != null) { foreach (BsonValue layer in layers) @@ -42,9 +47,11 @@ public void Apply(LiteRepository repository) MigratePropertyGroup(layer.AsDocument["LayerBrush"]?["PropertyGroup"].AsDocument); } } - - collection.Update(profileBson); + + profilesToUpdate.Add(profileBson); } + + collection.Update(profilesToUpdate); } private void MigrateProfileElement(BsonDocument profileElement) diff --git a/src/Artemis.Storage/Migrations/Storage/M0025NodeProvidersProfileConfig.cs b/src/Artemis.Storage/Migrations/Storage/M0025NodeProvidersProfileConfig.cs index b831bc03d..46d8c3fe7 100644 --- a/src/Artemis.Storage/Migrations/Storage/M0025NodeProvidersProfileConfig.cs +++ b/src/Artemis.Storage/Migrations/Storage/M0025NodeProvidersProfileConfig.cs @@ -1,4 +1,5 @@ -using LiteDB; +using System.Collections.Generic; +using LiteDB; namespace Artemis.Storage.Migrations.Storage; @@ -9,6 +10,7 @@ public class M0025NodeProvidersProfileConfig : IStorageMigration public void Apply(LiteRepository repository) { ILiteCollection categoryCollection = repository.Database.GetCollection("ProfileCategoryEntity"); + List toUpdate = new(); foreach (BsonDocument profileCategoryBson in categoryCollection.FindAll()) { BsonArray? profiles = profileCategoryBson["ProfileConfigurations"]?.AsArray; @@ -19,9 +21,11 @@ public void Apply(LiteRepository repository) profile["Version"] = 2; MigrateNodeScript(profile["ActivationCondition"]?.AsDocument); } + toUpdate.Add(profileCategoryBson); } - categoryCollection.Update(profileCategoryBson); } + + categoryCollection.Update(toUpdate); } private void MigrateNodeScript(BsonDocument? nodeScript)