1
0
mirror of https://github.com/bitwarden/server.git synced 2025-02-06 00:11:22 +01:00

Creat TVP prior to opening sql connection (#1411)

Data Table creation is slow. connection may be timing out while we create it.
This commit is contained in:
Matt Gibson 2021-06-24 19:40:46 -04:00 committed by GitHub
parent ee66d64c99
commit 61e41190b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -79,11 +79,12 @@ namespace Bit.Core.Repositories.SqlServer
public async Task<ICollection<string>> SelectKnownEmailsAsync(Guid organizationId, IEnumerable<string> emails,
bool onlyRegisteredUsers)
{
var emailsTvp = emails.ToArrayTVP("Email");
using (var connection = new SqlConnection(ConnectionString))
{
var result = await connection.QueryAsync<string>(
"[dbo].[OrganizationUser_SelectKnownEmails]",
new { OrganizationId = organizationId, Emails = emails.ToArrayTVP("Email"), OnlyUsers = onlyRegisteredUsers },
new { OrganizationId = organizationId, Emails = emailsTvp, OnlyUsers = onlyRegisteredUsers },
commandType: CommandType.StoredProcedure);
// Return as a list to avoid timing out the sql connection
@ -342,11 +343,12 @@ namespace Bit.Core.Repositories.SqlServer
organizationUser.SetNewId();
}
var orgUsersTVP = organizationUsers.ToTvp();
using (var connection = new SqlConnection(ConnectionString))
{
var results = await connection.ExecuteAsync(
$"[{Schema}].[{Table}_CreateMany]",
new { OrganizationUsersInput = organizationUsers.ToTvp() },
new { OrganizationUsersInput = orgUsersTVP },
commandType: CommandType.StoredProcedure);
}
}
@ -358,11 +360,12 @@ namespace Bit.Core.Repositories.SqlServer
return;
}
var orgUsersTVP = organizationUsers.ToTvp();
using (var connection = new SqlConnection(ConnectionString))
{
var results = await connection.ExecuteAsync(
$"[{Schema}].[{Table}_UpdateMany]",
new { OrganizationUsersInput = organizationUsers.ToTvp() },
new { OrganizationUsersInput = orgUsersTVP },
commandType: CommandType.StoredProcedure);
}
}