1
0
mirror of https://github.com/bitwarden/server synced 2025-12-15 07:43:54 +00:00

[PM-14476] Avoid multiple lookups in dictionaries (#4973)

* Avoid multiple lookups in dictionaries

* Consistency in fallback to empty CollectionIds

* Readability at the cost of lines changed

* Readability

* Changes after running dotnet format
This commit is contained in:
Henrik
2025-06-02 18:18:28 +02:00
committed by GitHub
parent 2c4393cc16
commit 8bac7f0145
44 changed files with 179 additions and 212 deletions

View File

@@ -312,13 +312,11 @@ public class CipherService : ICipherService
}
var attachments = cipher.GetAttachments();
if (!attachments.ContainsKey(attachmentId))
if (!attachments.TryGetValue(attachmentId, out var originalAttachmentMetadata))
{
throw new BadRequestException($"Cipher does not own specified attachment");
}
var originalAttachmentMetadata = attachments[attachmentId];
if (originalAttachmentMetadata.TempMetadata != null)
{
throw new BadRequestException("Another process is trying to migrate this attachment");
@@ -395,12 +393,11 @@ public class CipherService : ICipherService
{
var attachments = cipher?.GetAttachments() ?? new Dictionary<string, CipherAttachment.MetaData>();
if (!attachments.ContainsKey(attachmentId))
if (!attachments.TryGetValue(attachmentId, out var data))
{
throw new NotFoundException();
}
var data = attachments[attachmentId];
var response = new AttachmentResponseData
{
Cipher = cipher,