mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
handle bulk cipher events more efficiently
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Table;
|
||||
@ -9,6 +10,7 @@ namespace Bit.Core.Services
|
||||
{
|
||||
Task LogUserEventAsync(Guid userId, EventType type, DateTime? date = null);
|
||||
Task LogCipherEventAsync(Cipher cipher, EventType type, DateTime? date = null);
|
||||
Task LogCipherEventsAsync(IEnumerable<Tuple<Cipher, EventType, DateTime?>> events);
|
||||
Task LogCollectionEventAsync(Collection collection, EventType type, DateTime? date = null);
|
||||
Task LogGroupEventAsync(Group group, EventType type, DateTime? date = null);
|
||||
Task LogOrganizationUserEventAsync(OrganizationUser organizationUser, EventType type, DateTime? date = null);
|
||||
|
@ -68,11 +68,34 @@ namespace Bit.Core.Services
|
||||
}
|
||||
|
||||
public async Task LogCipherEventAsync(Cipher cipher, EventType type, DateTime? date = null)
|
||||
{
|
||||
var e = await BuildCipherEventMessageAsync(cipher, type, date);
|
||||
if(e != null)
|
||||
{
|
||||
await _eventWriteService.CreateAsync(e);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task LogCipherEventsAsync(IEnumerable<Tuple<Cipher, EventType, DateTime?>> events)
|
||||
{
|
||||
var cipherEvents = new List<IEvent>();
|
||||
foreach(var ev in events)
|
||||
{
|
||||
var e = await BuildCipherEventMessageAsync(ev.Item1, ev.Item2, ev.Item3);
|
||||
if(e != null)
|
||||
{
|
||||
cipherEvents.Add(e);
|
||||
}
|
||||
}
|
||||
await _eventWriteService.CreateManyAsync(cipherEvents);
|
||||
}
|
||||
|
||||
private async Task<EventMessage> BuildCipherEventMessageAsync(Cipher cipher, EventType type, DateTime? date = null)
|
||||
{
|
||||
// Only logging organization cipher events for now.
|
||||
if(!cipher.OrganizationId.HasValue || (!_currentContext?.UserId.HasValue ?? true))
|
||||
{
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
if(cipher.OrganizationId.HasValue)
|
||||
@ -80,11 +103,11 @@ namespace Bit.Core.Services
|
||||
var orgAbilities = await _applicationCacheService.GetOrganizationAbilitiesAsync();
|
||||
if(!CanUseEvents(orgAbilities, cipher.OrganizationId.Value))
|
||||
{
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
var e = new EventMessage(_currentContext)
|
||||
return new EventMessage(_currentContext)
|
||||
{
|
||||
OrganizationId = cipher.OrganizationId,
|
||||
UserId = cipher.OrganizationId.HasValue ? null : cipher.UserId,
|
||||
@ -93,7 +116,6 @@ namespace Bit.Core.Services
|
||||
ActingUserId = _currentContext?.UserId,
|
||||
Date = date.GetValueOrDefault(DateTime.UtcNow)
|
||||
};
|
||||
await _eventWriteService.CreateAsync(e);
|
||||
}
|
||||
|
||||
public async Task LogCollectionEventAsync(Collection collection, EventType type, DateTime? date = null)
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Table;
|
||||
@ -12,6 +13,11 @@ namespace Bit.Core.Services
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task LogCipherEventsAsync(IEnumerable<Tuple<Cipher, EventType, DateTime?>> events)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task LogCollectionEventAsync(Collection collection, EventType type, DateTime? date = null)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
|
Reference in New Issue
Block a user