Repository navigation
Expand file tree
/
Copy pathDatabaseMaintenanceTask.cs
More file actions
54 lines (47 loc) · 1.78 KB
/
Copy pathDatabaseMaintenanceTask.cs
File metadata and controls
54 lines (47 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Tasks;
namespace NotifySync
{
/// <summary>
/// Periodic SQLite maintenance: compacts the notifications database (VACUUM)
/// to reclaim free pages left behind by ongoing insert/delete churn. The DB is
/// small, so the rebuild is quick; running it off the hot path (a background
/// scheduled task) keeps it out of the request and event-handler paths.
/// </summary>
public class DatabaseMaintenanceTask : IScheduledTask
{
/// <inheritdoc />
public string Name => "NotifySync: Database Maintenance";
/// <inheritdoc />
public string Key => "NotifySyncDatabaseMaintenanceTask";
/// <inheritdoc />
public string Description => "Compacte la base de données NotifySync (VACUUM) pour récupérer l'espace libéré par les ajouts/suppressions.";
/// <inheritdoc />
public string Category => "NotifySync";
/// <inheritdoc />
public Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
{
var db = NotificationManager.Instance?.Db;
if (db == null)
{
return Task.CompletedTask;
}
return Task.Run(() => db.Vacuum(), cancellationToken);
}
/// <inheritdoc />
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
return new[]
{
new TaskTriggerInfo
{
Type = TaskTriggerInfoType.IntervalTrigger,
IntervalTicks = TimeSpan.FromDays(7).Ticks
}
};
}
}
}