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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user