mirror of
https://github.com/bitwarden/server.git
synced 2025-07-06 10:32:49 -05: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:
@ -79,11 +79,12 @@ namespace Bit.Core.Repositories.SqlServer
|
|||||||
public async Task<ICollection<string>> SelectKnownEmailsAsync(Guid organizationId, IEnumerable<string> emails,
|
public async Task<ICollection<string>> SelectKnownEmailsAsync(Guid organizationId, IEnumerable<string> emails,
|
||||||
bool onlyRegisteredUsers)
|
bool onlyRegisteredUsers)
|
||||||
{
|
{
|
||||||
|
var emailsTvp = emails.ToArrayTVP("Email");
|
||||||
using (var connection = new SqlConnection(ConnectionString))
|
using (var connection = new SqlConnection(ConnectionString))
|
||||||
{
|
{
|
||||||
var result = await connection.QueryAsync<string>(
|
var result = await connection.QueryAsync<string>(
|
||||||
"[dbo].[OrganizationUser_SelectKnownEmails]",
|
"[dbo].[OrganizationUser_SelectKnownEmails]",
|
||||||
new { OrganizationId = organizationId, Emails = emails.ToArrayTVP("Email"), OnlyUsers = onlyRegisteredUsers },
|
new { OrganizationId = organizationId, Emails = emailsTvp, OnlyUsers = onlyRegisteredUsers },
|
||||||
commandType: CommandType.StoredProcedure);
|
commandType: CommandType.StoredProcedure);
|
||||||
|
|
||||||
// Return as a list to avoid timing out the sql connection
|
// Return as a list to avoid timing out the sql connection
|
||||||
@ -342,11 +343,12 @@ namespace Bit.Core.Repositories.SqlServer
|
|||||||
organizationUser.SetNewId();
|
organizationUser.SetNewId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var orgUsersTVP = organizationUsers.ToTvp();
|
||||||
using (var connection = new SqlConnection(ConnectionString))
|
using (var connection = new SqlConnection(ConnectionString))
|
||||||
{
|
{
|
||||||
var results = await connection.ExecuteAsync(
|
var results = await connection.ExecuteAsync(
|
||||||
$"[{Schema}].[{Table}_CreateMany]",
|
$"[{Schema}].[{Table}_CreateMany]",
|
||||||
new { OrganizationUsersInput = organizationUsers.ToTvp() },
|
new { OrganizationUsersInput = orgUsersTVP },
|
||||||
commandType: CommandType.StoredProcedure);
|
commandType: CommandType.StoredProcedure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -358,11 +360,12 @@ namespace Bit.Core.Repositories.SqlServer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var orgUsersTVP = organizationUsers.ToTvp();
|
||||||
using (var connection = new SqlConnection(ConnectionString))
|
using (var connection = new SqlConnection(ConnectionString))
|
||||||
{
|
{
|
||||||
var results = await connection.ExecuteAsync(
|
var results = await connection.ExecuteAsync(
|
||||||
$"[{Schema}].[{Table}_UpdateMany]",
|
$"[{Schema}].[{Table}_UpdateMany]",
|
||||||
new { OrganizationUsersInput = organizationUsers.ToTvp() },
|
new { OrganizationUsersInput = orgUsersTVP },
|
||||||
commandType: CommandType.StoredProcedure);
|
commandType: CommandType.StoredProcedure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user