mirror of
https://github.com/bitwarden/server
synced 2025-12-14 23:33:41 +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:
@@ -129,13 +129,13 @@ public class CipherDetailsResponseModel : CipherResponseModel
|
||||
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphers, string obj = "cipherDetails")
|
||||
: base(cipher, user, organizationAbilities, globalSettings, obj)
|
||||
{
|
||||
if (collectionCiphers?.ContainsKey(cipher.Id) ?? false)
|
||||
if (collectionCiphers?.TryGetValue(cipher.Id, out var collectionCipher) ?? false)
|
||||
{
|
||||
CollectionIds = collectionCiphers[cipher.Id].Select(c => c.CollectionId);
|
||||
CollectionIds = collectionCipher.Select(c => c.CollectionId);
|
||||
}
|
||||
else
|
||||
{
|
||||
CollectionIds = new Guid[] { };
|
||||
CollectionIds = [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ public class CipherDetailsResponseModel : CipherResponseModel
|
||||
IEnumerable<CollectionCipher> collectionCiphers, string obj = "cipherDetails")
|
||||
: base(cipher, user, organizationAbilities, globalSettings, obj)
|
||||
{
|
||||
CollectionIds = collectionCiphers?.Select(c => c.CollectionId) ?? new List<Guid>();
|
||||
CollectionIds = collectionCiphers?.Select(c => c.CollectionId) ?? [];
|
||||
}
|
||||
|
||||
public CipherDetailsResponseModel(
|
||||
@@ -158,7 +158,7 @@ public class CipherDetailsResponseModel : CipherResponseModel
|
||||
string obj = "cipherDetails")
|
||||
: base(cipher, user, organizationAbilities, globalSettings, obj)
|
||||
{
|
||||
CollectionIds = cipher.CollectionIds ?? new List<Guid>();
|
||||
CollectionIds = cipher.CollectionIds ?? [];
|
||||
}
|
||||
|
||||
public IEnumerable<Guid> CollectionIds { get; set; }
|
||||
@@ -170,13 +170,13 @@ public class CipherMiniDetailsResponseModel : CipherMiniResponseModel
|
||||
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphers, bool orgUseTotp, string obj = "cipherMiniDetails")
|
||||
: base(cipher, globalSettings, orgUseTotp, obj)
|
||||
{
|
||||
if (collectionCiphers?.ContainsKey(cipher.Id) ?? false)
|
||||
if (collectionCiphers?.TryGetValue(cipher.Id, out var collectionCipher) ?? false)
|
||||
{
|
||||
CollectionIds = collectionCiphers[cipher.Id].Select(c => c.CollectionId);
|
||||
CollectionIds = collectionCipher.Select(c => c.CollectionId);
|
||||
}
|
||||
else
|
||||
{
|
||||
CollectionIds = new Guid[] { };
|
||||
CollectionIds = [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ public class CipherMiniDetailsResponseModel : CipherMiniResponseModel
|
||||
GlobalSettings globalSettings, bool orgUseTotp, string obj = "cipherMiniDetails")
|
||||
: base(cipher, globalSettings, orgUseTotp, obj)
|
||||
{
|
||||
CollectionIds = cipher.CollectionIds ?? new List<Guid>();
|
||||
CollectionIds = cipher.CollectionIds ?? [];
|
||||
}
|
||||
|
||||
public CipherMiniDetailsResponseModel(CipherOrganizationDetailsWithCollections cipher,
|
||||
|
||||
Reference in New Issue
Block a user