1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-19 03:58:13 -05:00
bitwarden/src/Infrastructure.Dapper/Repositories/MaintenanceRepository.cs
Justin Baur 1e0182008b
[PM-2943] Enable Nullable Repositories in Unowned Files (#4549)
* Enable Nullable In Unowned Repos

* Update More Tests

* Move to One If

* Fix Collections

* Format

* Add Migrations

* Move Pragma Annotation

* Add Better Assert Message
2024-07-24 09:48:09 -04:00

79 lines
2.5 KiB
C#

using System.Data;
using Bit.Core.Repositories;
using Bit.Core.Settings;
using Dapper;
using Microsoft.Data.SqlClient;
#nullable enable
namespace Bit.Infrastructure.Dapper.Repositories;
public class MaintenanceRepository : BaseRepository, IMaintenanceRepository
{
public MaintenanceRepository(GlobalSettings globalSettings)
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
{ }
public MaintenanceRepository(string connectionString, string readOnlyConnectionString)
: base(connectionString, readOnlyConnectionString)
{ }
public async Task UpdateStatisticsAsync()
{
using (var connection = new SqlConnection(ConnectionString))
{
await connection.ExecuteAsync(
"[dbo].[AzureSQLMaintenance]",
new { operation = "statistics", mode = "smart", LogToTable = true },
commandType: CommandType.StoredProcedure,
commandTimeout: 172800);
}
}
public async Task DisableCipherAutoStatsAsync()
{
using (var connection = new SqlConnection(ConnectionString))
{
await connection.ExecuteAsync(
"sp_autostats",
new { tblname = "[dbo].[Cipher]", flagc = "OFF" },
commandType: CommandType.StoredProcedure);
}
}
public async Task RebuildIndexesAsync()
{
using (var connection = new SqlConnection(ConnectionString))
{
await connection.ExecuteAsync(
"[dbo].[AzureSQLMaintenance]",
new { operation = "index", mode = "smart", LogToTable = true },
commandType: CommandType.StoredProcedure,
commandTimeout: 172800);
}
}
public async Task DeleteExpiredGrantsAsync()
{
using (var connection = new SqlConnection(ConnectionString))
{
await connection.ExecuteAsync(
"[dbo].[Grant_DeleteExpired]",
commandType: CommandType.StoredProcedure,
commandTimeout: 172800);
}
}
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);
}
}
}