1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 00:22:50 -05:00

batch events

This commit is contained in:
Kyle Spearrin
2019-07-25 15:50:13 -04:00
parent 675b22cc9f
commit 6a91fd6be9
3 changed files with 41 additions and 4 deletions

View File

@ -65,6 +65,32 @@ namespace Bit.Core.Utilities
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 DataTable ToGuidIdArrayTVP(this IEnumerable<Guid> ids)
{
return ids.ToArrayTVP("GuidId");