Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,17 @@ public async Task CreateManyAsync(IEnumerable<IEvent> entities)
var tableEvents = entities.Select(e => e as Core.Entities.Event ?? new Core.Entities.Event(e));
var entityEvents = Mapper.Map<List<Event>>(tableEvents);
entityEvents.ForEach(e => e.SetNewId());
await dbContext.BulkCopyAsync(entityEvents);
// SQLite does not support LinqToDB BulkCopy; use EF Core directly instead
if (dbContext.Database.IsSqlite())
{
await dbContext.AddRangeAsync(entityEvents);
await dbContext.SaveChangesAsync();
}
else
{
await dbContext.BulkCopyAsync(entityEvents);
await dbContext.SaveChangesAsync();
}
Comment thread
Banrion marked this conversation as resolved.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,18 @@ public async Task CreateAsync(Guid userId, IEnumerable<Core.Vault.Entities.Ciphe
{
var dbContext = GetDatabaseContext(scope);
var folderEntities = Mapper.Map<List<Folder>>(folders);
await dbContext.BulkCopyAsync(base.DefaultBulkCopyOptions, folderEntities);
var cipherEntities = Mapper.Map<List<Cipher>>(ciphers);
await dbContext.BulkCopyAsync(base.DefaultBulkCopyOptions, cipherEntities);
// SQLite does not support LinqToDB BulkCopy; use EF Core directly instead
if (dbContext.Database.IsSqlite())
{
await dbContext.AddRangeAsync(folderEntities);
await dbContext.AddRangeAsync(cipherEntities);
}
else
{
await dbContext.BulkCopyAsync(base.DefaultBulkCopyOptions, folderEntities);
await dbContext.BulkCopyAsync(base.DefaultBulkCopyOptions, cipherEntities);
}
await dbContext.UserBumpAccountRevisionDateAsync(userId);

await dbContext.SaveChangesAsync();
Expand All @@ -181,24 +190,44 @@ public async Task CreateAsync(IEnumerable<Core.Vault.Entities.Cipher> ciphers,
{
var dbContext = GetDatabaseContext(scope);
var cipherEntities = Mapper.Map<List<Cipher>>(ciphers);
await dbContext.BulkCopyAsync(base.DefaultBulkCopyOptions, cipherEntities);

if (collections.Any())
// SQLite does not support LinqToDB BulkCopy; use EF Core directly instead
if (dbContext.Database.IsSqlite())
{
var collectionEntities = Mapper.Map<List<Collection>>(collections);
await dbContext.BulkCopyAsync(base.DefaultBulkCopyOptions, collectionEntities);
await dbContext.AddRangeAsync(cipherEntities);
if (collections.Any())
{
await dbContext.AddRangeAsync(Mapper.Map<List<Collection>>(collections));
}
if (collectionCiphers.Any())
{
await dbContext.AddRangeAsync(Mapper.Map<List<CollectionCipher>>(collectionCiphers));
}
if (collectionUsers.Any())
{
await dbContext.AddRangeAsync(Mapper.Map<List<CollectionUser>>(collectionUsers));
}
}

if (collectionCiphers.Any())
else
{
var collectionCipherEntities = Mapper.Map<List<CollectionCipher>>(collectionCiphers);
await dbContext.BulkCopyAsync(base.DefaultBulkCopyOptions, collectionCipherEntities);
}
await dbContext.BulkCopyAsync(base.DefaultBulkCopyOptions, cipherEntities);

if (collectionUsers.Any())
{
var collectionUserEntities = Mapper.Map<List<CollectionUser>>(collectionUsers);
await dbContext.BulkCopyAsync(base.DefaultBulkCopyOptions, collectionUserEntities);
if (collections.Any())
{
var collectionEntities = Mapper.Map<List<Collection>>(collections);
await dbContext.BulkCopyAsync(base.DefaultBulkCopyOptions, collectionEntities);
}

if (collectionCiphers.Any())
{
var collectionCipherEntities = Mapper.Map<List<CollectionCipher>>(collectionCiphers);
await dbContext.BulkCopyAsync(base.DefaultBulkCopyOptions, collectionCipherEntities);
}

if (collectionUsers.Any())
{
var collectionUserEntities = Mapper.Map<List<CollectionUser>>(collectionUsers);
await dbContext.BulkCopyAsync(base.DefaultBulkCopyOptions, collectionUserEntities);
}
}

await dbContext.UserBumpAccountRevisionDateByOrganizationIdAsync(ciphers.First().OrganizationId.Value);
Expand Down
Loading