mirror of
https://github.com/bitwarden/server
synced 2026-01-02 00:23:40 +00:00
[PM-25138] Reduce db locking when creating default collections (#6308)
* Use single method for default collection creation * Use GenerateComb to create sequential guids * Pre-sort data for SqlBulkCopy * Add SqlBulkCopy options per dbops recommendations
This commit is contained in:
26
src/Infrastructure.Dapper/Utilities/SqlGuidHelpers.cs
Normal file
26
src/Infrastructure.Dapper/Utilities/SqlGuidHelpers.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Data.SqlTypes;
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Utilities;
|
||||
|
||||
public static class SqlGuidHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Sorts the source IEnumerable by the specified Guid property using the <see cref="SqlGuid"/> comparison logic.
|
||||
/// This is required because MSSQL server compares (and therefore sorts) Guids differently to C#.
|
||||
/// Ref: https://learn.microsoft.com/en-us/sql/connect/ado-net/sql/compare-guid-uniqueidentifier-values
|
||||
/// </summary>
|
||||
public static IOrderedEnumerable<T> OrderBySqlGuid<T>(
|
||||
this IEnumerable<T> source,
|
||||
Func<T, Guid> keySelector)
|
||||
{
|
||||
return source.OrderBy(x => new SqlGuid(keySelector(x)));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="OrderBySqlGuid"/>
|
||||
public static IOrderedEnumerable<T> ThenBySqlGuid<T>(
|
||||
this IOrderedEnumerable<T> source,
|
||||
Func<T, Guid> keySelector)
|
||||
{
|
||||
return source.ThenBy(x => new SqlGuid(keySelector(x)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user