mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
cache ciphers on events lookup
This commit is contained in:
@ -40,6 +40,7 @@ namespace Bit.Events.Controllers
|
||||
return new BadRequestResult();
|
||||
}
|
||||
var cipherEvents = new List<Tuple<Cipher, EventType, DateTime?>>();
|
||||
var ciphersCache = new Dictionary<Guid, Cipher>();
|
||||
foreach(var eventModel in model)
|
||||
{
|
||||
switch(eventModel.Type)
|
||||
@ -61,12 +62,24 @@ namespace Bit.Events.Controllers
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var cipher = await _cipherRepository.GetByIdAsync(eventModel.CipherId.Value,
|
||||
_currentContext.UserId.Value);
|
||||
Cipher cipher = null;
|
||||
if(ciphersCache.ContainsKey(eventModel.CipherId.Value))
|
||||
{
|
||||
cipher = ciphersCache[eventModel.CipherId.Value];
|
||||
}
|
||||
else
|
||||
{
|
||||
cipher = await _cipherRepository.GetByIdAsync(eventModel.CipherId.Value,
|
||||
_currentContext.UserId.Value);
|
||||
}
|
||||
if(cipher == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(!ciphersCache.ContainsKey(eventModel.CipherId.Value))
|
||||
{
|
||||
ciphersCache.Add(eventModel.CipherId.Value, cipher);
|
||||
}
|
||||
cipherEvents.Add(new Tuple<Cipher, EventType, DateTime?>(cipher, eventModel.Type, eventModel.Date));
|
||||
break;
|
||||
default:
|
||||
|
Reference in New Issue
Block a user