No rate limiting saves
This commit is contained in:
parent
2a6d824cc9
commit
3d285b0b6e
3 changed files with 15 additions and 54 deletions
|
|
@ -155,10 +155,10 @@ export class SyncSettingsTab extends PluginSettingTab {
|
||||||
text: "Show history"
|
text: "Show history"
|
||||||
},
|
},
|
||||||
(button) =>
|
(button) =>
|
||||||
(button.onclick = async (): Promise<void> => {
|
(button.onclick = async (): Promise<void> => {
|
||||||
this.plugin.closeSettings();
|
this.plugin.closeSettings();
|
||||||
await this.plugin.activateView(HistoryView.TYPE);
|
await this.plugin.activateView(HistoryView.TYPE);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
buttonContainer.createEl(
|
buttonContainer.createEl(
|
||||||
|
|
@ -167,10 +167,10 @@ export class SyncSettingsTab extends PluginSettingTab {
|
||||||
text: "Show logs"
|
text: "Show logs"
|
||||||
},
|
},
|
||||||
(button) =>
|
(button) =>
|
||||||
(button.onclick = async (): Promise<void> => {
|
(button.onclick = async (): Promise<void> => {
|
||||||
this.plugin.closeSettings();
|
this.plugin.closeSettings();
|
||||||
await this.plugin.activateView(LogsView.TYPE);
|
await this.plugin.activateView(LogsView.TYPE);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
@ -301,7 +301,7 @@ export class SyncSettingsTab extends PluginSettingTab {
|
||||||
toggle
|
toggle
|
||||||
.setValue(
|
.setValue(
|
||||||
this.syncEnabledOverride ??
|
this.syncEnabledOverride ??
|
||||||
this.syncClient.getSettings().isSyncEnabled
|
this.syncClient.getSettings().isSyncEnabled
|
||||||
)
|
)
|
||||||
.setDisabled(this.isApplyingChanges)
|
.setDisabled(this.isApplyingChanges)
|
||||||
.setTooltip(
|
.setTooltip(
|
||||||
|
|
@ -468,39 +468,7 @@ export class SyncSettingsTab extends PluginSettingTab {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
new Setting(containerEl)
|
|
||||||
.setName("Minimum save interval (ms)")
|
|
||||||
.setDesc(
|
|
||||||
"The minimum time between saving settings and database to disk, in milliseconds. Lower values save more frequently but may impact performance."
|
|
||||||
)
|
|
||||||
.addText((input) =>
|
|
||||||
input
|
|
||||||
.setValue(
|
|
||||||
this.syncClient
|
|
||||||
.getSettings()
|
|
||||||
.minimumSaveIntervalMs.toString()
|
|
||||||
)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
if (value === "") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let parsedValue = Number.parseInt(value, 10);
|
|
||||||
if (Number.isNaN(parsedValue) || parsedValue < 0) {
|
|
||||||
parsedValue =
|
|
||||||
this.syncClient.getSettings()
|
|
||||||
.minimumSaveIntervalMs;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value !== parsedValue.toString()) {
|
|
||||||
input.setValue(parsedValue.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.syncClient.setSetting(
|
|
||||||
"minimumSaveIntervalMs",
|
|
||||||
parsedValue
|
|
||||||
);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private setStatusDescriptionSubscription(
|
private setStatusDescriptionSubscription(
|
||||||
|
|
@ -524,9 +492,9 @@ export class SyncSettingsTab extends PluginSettingTab {
|
||||||
name: string,
|
name: string,
|
||||||
settingName: keyof SyncSettings
|
settingName: keyof SyncSettings
|
||||||
): [
|
): [
|
||||||
DocumentFragment,
|
DocumentFragment,
|
||||||
(newValue: SyncSettings[keyof SyncSettings]) => unknown
|
(newValue: SyncSettings[keyof SyncSettings]) => unknown
|
||||||
] {
|
] {
|
||||||
const titleContainer = document.createDocumentFragment();
|
const titleContainer = document.createDocumentFragment();
|
||||||
const title = titleContainer.createEl("div", {
|
const title = titleContainer.createEl("div", {
|
||||||
text: name,
|
text: name,
|
||||||
|
|
@ -536,11 +504,10 @@ export class SyncSettingsTab extends PluginSettingTab {
|
||||||
const updateTitle = (
|
const updateTitle = (
|
||||||
currentValue: SyncSettings[keyof SyncSettings]
|
currentValue: SyncSettings[keyof SyncSettings]
|
||||||
): void => {
|
): void => {
|
||||||
title.innerText = `${name}${
|
title.innerText = `${name}${currentValue !== this.syncClient.getSettings()[settingName]
|
||||||
currentValue !== this.syncClient.getSettings()[settingName]
|
|
||||||
? " (unsaved)"
|
? " (unsaved)"
|
||||||
: ""
|
: ""
|
||||||
}`;
|
}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
return [titleContainer, updateTitle];
|
return [titleContainer, updateTitle];
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ export interface SyncSettings {
|
||||||
diffCacheSizeMB: number;
|
diffCacheSizeMB: number;
|
||||||
enableTelemetry: boolean;
|
enableTelemetry: boolean;
|
||||||
networkRetryIntervalMs: number;
|
networkRetryIntervalMs: number;
|
||||||
minimumSaveIntervalMs: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_SETTINGS: SyncSettings = {
|
export const DEFAULT_SETTINGS: SyncSettings = {
|
||||||
|
|
@ -29,7 +28,6 @@ export const DEFAULT_SETTINGS: SyncSettings = {
|
||||||
diffCacheSizeMB: 4,
|
diffCacheSizeMB: 4,
|
||||||
enableTelemetry: false,
|
enableTelemetry: false,
|
||||||
networkRetryIntervalMs: 1000,
|
networkRetryIntervalMs: 1000,
|
||||||
minimumSaveIntervalMs: 1000
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Settings {
|
export class Settings {
|
||||||
|
|
|
||||||
|
|
@ -150,10 +150,6 @@ export class SyncClient {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const rateLimitedSave = rateLimit(
|
|
||||||
persistence.save,
|
|
||||||
() => settings.getSettings().minimumSaveIntervalMs
|
|
||||||
);
|
|
||||||
|
|
||||||
const syncEventQueue = new SyncEventQueue(
|
const syncEventQueue = new SyncEventQueue(
|
||||||
settings,
|
settings,
|
||||||
|
|
@ -161,7 +157,7 @@ export class SyncClient {
|
||||||
state.database,
|
state.database,
|
||||||
async (data): Promise<void> => {
|
async (data): Promise<void> => {
|
||||||
state = { ...state, database: data };
|
state = { ...state, database: data };
|
||||||
await rateLimitedSave(state);
|
await persistence.save(state);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue