1
0
mirror of https://github.com/bitwarden/server synced 2025-12-25 04:33:26 +00:00

[PM-24357] Do not purge ciphers in the default collection (#6320)

* do not purge ciphers in the default collection

* Update `DeleteByOrganizationId` procedure to be more performant based on PR review feedback

* update EF integration for purge to match new SQL implementation

* update Cipher_DeleteByOrganizationId based on PR feedback from dbops team
This commit is contained in:
Nick Krantz
2025-09-24 12:52:04 -05:00
committed by GitHub
parent 6e4f05ebd3
commit 6edab46d97
4 changed files with 345 additions and 49 deletions

View File

@@ -281,17 +281,20 @@ public class CipherRepository : Repository<Core.Vault.Entities.Cipher, Cipher, G
{
var dbContext = GetDatabaseContext(scope);
var collectionCiphers = from cc in dbContext.CollectionCiphers
join c in dbContext.Collections
on cc.CollectionId equals c.Id
where c.OrganizationId == organizationId
select cc;
dbContext.RemoveRange(collectionCiphers);
var ciphersToDelete = from c in dbContext.Ciphers
where c.OrganizationId == organizationId
&& !c.CollectionCiphers.Any(cc =>
cc.Collection.Type == CollectionType.DefaultUserCollection)
select c;
dbContext.RemoveRange(ciphersToDelete);
var ciphers = from c in dbContext.Ciphers
where c.OrganizationId == organizationId
select c;
dbContext.RemoveRange(ciphers);
var collectionCiphersToRemove = from cc in dbContext.CollectionCiphers
join col in dbContext.Collections on cc.CollectionId equals col.Id
join c in dbContext.Ciphers on cc.CipherId equals c.Id
where col.Type != CollectionType.DefaultUserCollection
&& c.OrganizationId == organizationId
select cc;
dbContext.RemoveRange(collectionCiphersToRemove);
await OrganizationUpdateStorage(organizationId);
await dbContext.UserBumpAccountRevisionDateByOrganizationIdAsync(organizationId);