fix: run compaction every interval (#834)

This commit is contained in:
Liu Xiaoyi
2024-12-18 02:47:40 +08:00
committed by GitHub
parent 059c3b4ebb
commit 99a1b6bbd0
4 changed files with 8 additions and 0 deletions

View File

@@ -31,6 +31,7 @@ class Users {
}); });
db.ensureIndex({fieldName: 'username', unique: true}); db.ensureIndex({fieldName: 'username', unique: true});
db.setAutocompactionInterval(config.dbCleanInterval);
return db; return db;
})(); })();

View File

@@ -21,6 +21,7 @@ class FeedService extends BaseService<Record<string, never>> {
constructor(...args: ConstructorParameters<typeof BaseService>) { constructor(...args: ConstructorParameters<typeof BaseService>) {
super(...args); super(...args);
this.db.setAutocompactionInterval(config.dbCleanInterval);
this.onServicesUpdated = async () => { this.onServicesUpdated = async () => {
// Execute once only. // Execute once only.

View File

@@ -26,6 +26,7 @@ class NotificationService extends BaseService<NotificationServiceEvents> {
constructor(...args: ConstructorParameters<typeof BaseService>) { constructor(...args: ConstructorParameters<typeof BaseService>) {
super(...args); super(...args);
this.db.setAutocompactionInterval(config.dbCleanInterval);
(async () => { (async () => {
const notifications = await this.db.findAsync<Notification>({}).catch(() => undefined); const notifications = await this.db.findAsync<Notification>({}).catch(() => undefined);

View File

@@ -21,6 +21,11 @@ class SettingService extends BaseService<SettingServiceEvents> {
filename: path.join(config.dbPath, this.user._id, 'settings', 'settings.db'), filename: path.join(config.dbPath, this.user._id, 'settings', 'settings.db'),
}); });
constructor(...args: ConstructorParameters<typeof BaseService>) {
super(...args);
this.db.setAutocompactionInterval(config.dbCleanInterval);
}
async destroy(drop: boolean) { async destroy(drop: boolean) {
if (drop) { if (drop) {
await this.db.dropDatabaseAsync(); await this.db.dropDatabaseAsync();