2022-05-10 17:12:09 -04:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Data;
|
2018-10-09 10:12:27 -04:00
|
|
|
|
using System.Data.SqlClient;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2022-01-11 10:40:51 +01:00
|
|
|
|
using Bit.Core.Repositories;
|
2021-02-22 15:35:16 -06:00
|
|
|
|
using Bit.Core.Settings;
|
2018-10-09 10:12:27 -04:00
|
|
|
|
using Dapper;
|
|
|
|
|
|
|
2022-01-11 10:40:51 +01:00
|
|
|
|
namespace Bit.Infrastructure.Dapper.Repositories
|
2018-10-09 10:12:27 -04:00
|
|
|
|
{
|
|
|
|
|
|
public class MaintenanceRepository : BaseRepository, IMaintenanceRepository
|
|
|
|
|
|
{
|
|
|
|
|
|
public MaintenanceRepository(GlobalSettings globalSettings)
|
2018-10-09 17:21:12 -04:00
|
|
|
|
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
2018-10-09 10:12:27 -04:00
|
|
|
|
{ }
|
|
|
|
|
|
|
2018-10-09 17:21:12 -04:00
|
|
|
|
public MaintenanceRepository(string connectionString, string readOnlyConnectionString)
|
|
|
|
|
|
: base(connectionString, readOnlyConnectionString)
|
2018-10-09 10:12:27 -04:00
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
public async Task UpdateStatisticsAsync()
|
|
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
2018-10-09 10:12:27 -04:00
|
|
|
|
{
|
|
|
|
|
|
await connection.ExecuteAsync(
|
|
|
|
|
|
"[dbo].[AzureSQLMaintenance]",
|
|
|
|
|
|
new { operation = "statistics", mode = "smart", LogToTable = true },
|
|
|
|
|
|
commandType: CommandType.StoredProcedure,
|
2020-03-08 20:59:03 -04:00
|
|
|
|
commandTimeout: 172800);
|
2018-10-09 10:12:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-03 22:39:53 -05:00
|
|
|
|
public async Task DisableCipherAutoStatsAsync()
|
|
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
2019-02-03 22:39:53 -05:00
|
|
|
|
{
|
|
|
|
|
|
await connection.ExecuteAsync(
|
|
|
|
|
|
"sp_autostats",
|
|
|
|
|
|
new { tblname = "[dbo].[Cipher]", flagc = "OFF" },
|
|
|
|
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-09 10:12:27 -04:00
|
|
|
|
public async Task RebuildIndexesAsync()
|
|
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
2018-10-09 10:12:27 -04:00
|
|
|
|
{
|
|
|
|
|
|
await connection.ExecuteAsync(
|
|
|
|
|
|
"[dbo].[AzureSQLMaintenance]",
|
|
|
|
|
|
new { operation = "index", mode = "smart", LogToTable = true },
|
|
|
|
|
|
commandType: CommandType.StoredProcedure,
|
2020-03-08 20:59:03 -04:00
|
|
|
|
commandTimeout: 172800);
|
2018-10-09 10:12:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-10-09 10:23:52 -04:00
|
|
|
|
|
|
|
|
|
|
public async Task DeleteExpiredGrantsAsync()
|
|
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
2018-10-09 10:23:52 -04:00
|
|
|
|
{
|
|
|
|
|
|
await connection.ExecuteAsync(
|
|
|
|
|
|
"[dbo].[Grant_DeleteExpired]",
|
|
|
|
|
|
commandType: CommandType.StoredProcedure,
|
2020-03-08 20:59:03 -04:00
|
|
|
|
commandTimeout: 172800);
|
2018-10-09 10:23:52 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-05-10 17:12:09 -04:00
|
|
|
|
|
|
|
|
|
|
public async Task DeleteExpiredSponsorshipsAsync(DateTime validUntilBeforeDate)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
|
|
|
|
{
|
|
|
|
|
|
await connection.ExecuteAsync(
|
|
|
|
|
|
"[dbo].[OrganizationSponsorship_DeleteExpired]",
|
|
|
|
|
|
new { ValidUntilBeforeDate = validUntilBeforeDate },
|
|
|
|
|
|
commandType: CommandType.StoredProcedure,
|
|
|
|
|
|
commandTimeout: 172800);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-10-09 10:12:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|