1
0
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:
Kyle Spearrin
2019-07-25 16:29:34 -04:00
parent 6a91fd6be9
commit fcdac6415a

View File

@ -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: