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(); return new BadRequestResult();
} }
var cipherEvents = new List<Tuple<Cipher, EventType, DateTime?>>(); var cipherEvents = new List<Tuple<Cipher, EventType, DateTime?>>();
var ciphersCache = new Dictionary<Guid, Cipher>();
foreach(var eventModel in model) foreach(var eventModel in model)
{ {
switch(eventModel.Type) switch(eventModel.Type)
@ -61,12 +62,24 @@ namespace Bit.Events.Controllers
{ {
continue; continue;
} }
var cipher = await _cipherRepository.GetByIdAsync(eventModel.CipherId.Value, Cipher cipher = null;
_currentContext.UserId.Value); 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) if(cipher == null)
{ {
continue; 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)); cipherEvents.Add(new Tuple<Cipher, EventType, DateTime?>(cipher, eventModel.Type, eventModel.Date));
break; break;
default: default: