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:
@ -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
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user