1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 23:52:50 -05:00

Remove Batch (#2274)

This commit is contained in:
Justin Baur
2022-09-14 14:57:05 -04:00
committed by GitHub
parent f848eb2477
commit 735ad264f1
5 changed files with 6 additions and 59 deletions

View File

@ -8,7 +8,6 @@ using Bit.Core.OrganizationFeatures.OrganizationSponsorships.FamiliesForEnterpri
using Bit.Core.Repositories;
using Bit.Core.Services;
using Bit.Core.Settings;
using Bit.Core.Utilities;
using Microsoft.Extensions.Logging;
namespace Bit.Core.OrganizationFeatures.OrganizationSponsorships.FamiliesForEnterprise.SelfHosted;
@ -71,7 +70,7 @@ public class SelfHostedSyncSponsorshipsCommand : BaseIdentityClientService, ISel
}
var syncedSponsorships = new List<OrganizationSponsorshipData>();
foreach (var orgSponsorshipsBatch in CoreHelpers.Batch(organizationSponsorshipsDict.Values, 1000))
foreach (var orgSponsorshipsBatch in organizationSponsorshipsDict.Values.Chunk(1000))
{
var response = await SendAsync<OrganizationSponsorshipSyncRequestModel, OrganizationSponsorshipSyncResponseModel>(HttpMethod.Post, "organization/sponsorship/sync", new OrganizationSponsorshipSyncRequestModel
{

View File

@ -403,7 +403,7 @@ public class CipherService : ICipherService
var events = deletingCiphers.Select(c =>
new Tuple<Cipher, EventType, DateTime?>(c, EventType.Cipher_Deleted, null));
foreach (var eventsBatch in events.Batch(100))
foreach (var eventsBatch in events.Chunk(100))
{
await _eventService.LogCipherEventsAsync(eventsBatch);
}
@ -574,7 +574,7 @@ public class CipherService : ICipherService
var events = cipherInfos.Select(c =>
new Tuple<Cipher, EventType, DateTime?>(c.cipher, EventType.Cipher_Shared, null));
foreach (var eventsBatch in events.Batch(100))
foreach (var eventsBatch in events.Chunk(100))
{
await _eventService.LogCipherEventsAsync(eventsBatch);
}
@ -791,7 +791,7 @@ public class CipherService : ICipherService
var events = deletingCiphers.Select(c =>
new Tuple<Cipher, EventType, DateTime?>(c, EventType.Cipher_SoftDeleted, null));
foreach (var eventsBatch in events.Batch(100))
foreach (var eventsBatch in events.Chunk(100))
{
await _eventService.LogCipherEventsAsync(eventsBatch);
}
@ -840,7 +840,7 @@ public class CipherService : ICipherService
c.DeletedDate = null;
return new Tuple<Cipher, EventType, DateTime?>(c, EventType.Cipher_Restored, null);
});
foreach (var eventsBatch in events.Batch(100))
foreach (var eventsBatch in events.Chunk(100))
{
await _eventService.LogCipherEventsAsync(eventsBatch);
}

View File

@ -70,32 +70,6 @@ public static class CoreHelpers
return new Guid(guidArray);
}
public static IEnumerable<IEnumerable<T>> Batch<T>(this IEnumerable<T> source, int size)
{
T[] bucket = null;
var count = 0;
foreach (var item in source)
{
if (bucket == null)
{
bucket = new T[size];
}
bucket[count++] = item;
if (count != size)
{
continue;
}
yield return bucket.Select(x => x);
bucket = null;
count = 0;
}
// Return the last bucket with all remaining elements
if (bucket != null && count > 0)
{
yield return bucket.Take(count);
}
}
public static string CleanCertificateThumbprint(string thumbprint)
{
// Clean possible garbage characters from thumbprint copy/paste