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:
42
src/Core/Repositories/SqlServer/MaintenanceRepository.cs
Normal file
42
src/Core/Repositories/SqlServer/MaintenanceRepository.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user