Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Fix race condition on vault import with multiple folders (#1786)

Leendert de Borstdb9d8e3ead0b
diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor
index 2c2948a19..f651eff04 100644
--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor
+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor
@@ -804,8 +804,9 @@
}
}
- // Create new folder with parent relationship
- var newFolderId = await FolderService.CreateAsync(folderName, parentFolderId);
+ // Create new folder with parent relationship. Skip per-folder background sync —
+ // the final DbService.SaveDatabaseAsync() at the end of the import covers all mutations.
+ var newFolderId = await FolderService.CreateAsync(folderName, parentFolderId, syncToServer: false);
folderPathToId[folderPath] = newFolderId;
}
}
diff --git a/apps/server/AliasVault.Client/Services/FolderService.cs b/apps/server/AliasVault.Client/Services/FolderService.cs
index 48843cfab..471f1a895 100644
--- a/apps/server/AliasVault.Client/Services/FolderService.cs
+++ b/apps/server/AliasVault.Client/Services/FolderService.cs
@@ -91,8 +91,10 @@ public sealed class FolderService(DbService dbService)
/// </summary>
/// <param name="name">The folder name.</param>
/// <param name="parentFolderId">Optional parent folder ID.</param>
+ /// <param name="syncToServer">Whether to trigger a background sync to the server. Set to false when
+ /// the caller will batch multiple mutations and perform a single sync afterwards (e.g. bulk import).</param>
/// <returns>The created folder ID.</returns>
- public async Task<Guid> CreateAsync(string name, Guid? parentFolderId = null)
+ public async Task<Guid> CreateAsync(string name, Guid? parentFolderId = null, bool syncToServer = true)
{
var context = await dbService.GetDbContextAsync();
@@ -109,7 +111,11 @@ public sealed class FolderService(DbService dbService)
context.Folders.Add(folder);
await context.SaveChangesAsync();
- dbService.SaveDatabaseInBackground();
+
+ if (syncToServer)
+ {
+ dbService.SaveDatabaseInBackground();
+ }
return folder.Id;
}