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

This commit is contained in:
Leendert de Borst
2026-04-24 21:44:38 +02:00
committed by Leendert de Borst
parent c631326706
commit db9d8e3ead
2 changed files with 11 additions and 4 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}