From a68e09b70859424b0a4e0a1c50e4c07e9f3c6c70 Mon Sep 17 00:00:00 2001 From: Matt Gibson Date: Mon, 18 Oct 2021 13:12:30 -0400 Subject: [PATCH] Build TVP arrays outside connection SQL connections sometimes seem to time out while building these. We can pre-build them, so we should. --- .../SqlServer/OrganizationUserRepository.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Core/Repositories/SqlServer/OrganizationUserRepository.cs b/src/Core/Repositories/SqlServer/OrganizationUserRepository.cs index c0a3632be3..b5cce51f65 100644 --- a/src/Core/Repositories/SqlServer/OrganizationUserRepository.cs +++ b/src/Core/Repositories/SqlServer/OrganizationUserRepository.cs @@ -231,11 +231,12 @@ namespace Bit.Core.Repositories.SqlServer public async Task UpdateGroupsAsync(Guid orgUserId, IEnumerable groupIds) { + var tvpIds = groupIds.ToGuidIdArrayTVP(); using (var connection = new SqlConnection(ConnectionString)) { var results = await connection.ExecuteAsync( "[dbo].[GroupUser_UpdateGroups]", - new { OrganizationUserId = orgUserId, GroupIds = groupIds.ToGuidIdArrayTVP() }, + new { OrganizationUserId = orgUserId, GroupIds = tvpIds }, commandType: CommandType.StoredProcedure); } } @@ -275,11 +276,12 @@ namespace Bit.Core.Repositories.SqlServer public async Task> GetManyByManyUsersAsync(IEnumerable userIds) { + var tvpIds = userIds.ToGuidIdArrayTVP(); using (var connection = new SqlConnection(ConnectionString)) { var results = await connection.QueryAsync( "[dbo].[OrganizationUser_ReadByUserIds]", - new { UserIds = userIds.ToGuidIdArrayTVP() }, + new { UserIds = tvpIds }, commandType: CommandType.StoredProcedure); return results.ToList(); @@ -288,11 +290,12 @@ namespace Bit.Core.Repositories.SqlServer public async Task> GetManyAsync(IEnumerable Ids) { + var tvpIds = Ids.ToGuidIdArrayTVP(); using (var connection = new SqlConnection(ConnectionString)) { var results = await connection.QueryAsync( "[dbo].[OrganizationUser_ReadByIds]", - new { Ids = Ids.ToGuidIdArrayTVP() }, + new { Ids = tvpIds }, commandType: CommandType.StoredProcedure); return results.ToList(); @@ -314,10 +317,11 @@ namespace Bit.Core.Repositories.SqlServer public async Task DeleteManyAsync(IEnumerable organizationUserIds) { + var tvpIds = organizationUserIds.ToGuidIdArrayTVP(); using (var connection = new SqlConnection(ConnectionString)) { await connection.ExecuteAsync("[dbo].[OrganizationUser_DeleteByIds]", - new { Ids = organizationUserIds.ToGuidIdArrayTVP() }, commandType: CommandType.StoredProcedure); + new { Ids = tvpIds }, commandType: CommandType.StoredProcedure); } } @@ -385,11 +389,12 @@ namespace Bit.Core.Repositories.SqlServer public async Task> GetManyPublicKeysByOrganizationUserAsync( Guid organizationId, IEnumerable Ids) { + var tvpIds = Ids.ToGuidIdArrayTVP(); using (var connection = new SqlConnection(ConnectionString)) { var results = await connection.QueryAsync( "[dbo].[User_ReadPublicKeysByOrganizationUserIds]", - new { OrganizationId = organizationId, OrganizationUserIds = Ids.ToGuidIdArrayTVP() }, + new { OrganizationId = organizationId, OrganizationUserIds = tvpIds }, commandType: CommandType.StoredProcedure); return results.ToList();