mirror of
https://github.com/bitwarden/server
synced 2026-01-02 16:43:25 +00:00
database maintenance jobs setup in admin
This commit is contained in:
10
src/Core/Repositories/IMaintenanceRepository.cs
Normal file
10
src/Core/Repositories/IMaintenanceRepository.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
public interface IMaintenanceRepository
|
||||
{
|
||||
Task UpdateStatisticsAsync();
|
||||
Task RebuildIndexesAsync();
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,7 @@ namespace Bit.Core.Utilities
|
||||
services.AddSingleton<IGroupRepository, SqlServerRepos.GroupRepository>();
|
||||
services.AddSingleton<IU2fRepository, SqlServerRepos.U2fRepository>();
|
||||
services.AddSingleton<IInstallationRepository, SqlServerRepos.InstallationRepository>();
|
||||
services.AddSingleton<IMaintenanceRepository, SqlServerRepos.MaintenanceRepository>();
|
||||
|
||||
if(globalSettings.SelfHosted)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user