1
0
mirror of https://github.com/bitwarden/server synced 2025-12-28 06:03:29 +00:00

database maintenance jobs setup in admin

This commit is contained in:
Kyle Spearrin
2018-10-09 10:12:27 -04:00
parent 5bde617465
commit 5812915677
10 changed files with 624 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
using System.Data;
using System.Data.SqlClient;
using System.Threading.Tasks;
using Dapper;
namespace Bit.Core.Repositories.SqlServer
{
public class MaintenanceRepository : BaseRepository, IMaintenanceRepository
{
public MaintenanceRepository(GlobalSettings globalSettings)
: this(globalSettings.SqlServer.ConnectionString)
{ }
public MaintenanceRepository(string connectionString)
: base(connectionString)
{ }
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: 86400);
}
}
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: 86400);
}
}
}
}