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"
|
||||
},
|
||||
(button) =>
|
||||
(button.onclick = async (): Promise<void> => {
|
||||
this.plugin.closeSettings();
|
||||
await this.plugin.activateView(HistoryView.TYPE);
|
||||
})
|
||||
(button.onclick = async (): Promise<void> => {
|
||||
this.plugin.closeSettings();
|
||||
await this.plugin.activateView(HistoryView.TYPE);
|
||||
})
|
||||
);
|
||||
|
||||
buttonContainer.createEl(
|
||||
|
|
@ -167,10 +167,10 @@ export class SyncSettingsTab extends PluginSettingTab {
|
|||
text: "Show logs"
|
||||
},
|
||||
(button) =>
|
||||
(button.onclick = async (): Promise<void> => {
|
||||
this.plugin.closeSettings();
|
||||
await this.plugin.activateView(LogsView.TYPE);
|
||||
})
|
||||
(button.onclick = async (): Promise<void> => {
|
||||
this.plugin.closeSettings();
|
||||
await this.plugin.activateView(LogsView.TYPE);
|
||||
})
|
||||
);
|
||||
}
|
||||
);
|
||||
|
|
@ -301,7 +301,7 @@ export class SyncSettingsTab extends PluginSettingTab {
|
|||
toggle
|
||||
.setValue(
|
||||
this.syncEnabledOverride ??
|
||||
this.syncClient.getSettings().isSyncEnabled
|
||||
this.syncClient.getSettings().isSyncEnabled
|
||||
)
|
||||
.setDisabled(this.isApplyingChanges)
|
||||
.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(
|
||||
|
|
@ -524,9 +492,9 @@ export class SyncSettingsTab extends PluginSettingTab {
|
|||
name: string,
|
||||
settingName: keyof SyncSettings
|
||||
): [
|
||||
DocumentFragment,
|
||||
(newValue: SyncSettings[keyof SyncSettings]) => unknown
|
||||
] {
|
||||
DocumentFragment,
|
||||
(newValue: SyncSettings[keyof SyncSettings]) => unknown
|
||||
] {
|
||||
const titleContainer = document.createDocumentFragment();
|
||||
const title = titleContainer.createEl("div", {
|
||||
text: name,
|
||||
|
|
@ -536,11 +504,10 @@ export class SyncSettingsTab extends PluginSettingTab {
|
|||
const updateTitle = (
|
||||
currentValue: SyncSettings[keyof SyncSettings]
|
||||
): void => {
|
||||
title.innerText = `${name}${
|
||||
currentValue !== this.syncClient.getSettings()[settingName]
|
||||
title.innerText = `${name}${currentValue !== this.syncClient.getSettings()[settingName]
|
||||
? " (unsaved)"
|
||||
: ""
|
||||
}`;
|
||||
}`;
|
||||
};
|
||||
|
||||
return [titleContainer, updateTitle];
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ export interface SyncSettings {
|
|||
diffCacheSizeMB: number;
|
||||
enableTelemetry: boolean;
|
||||
networkRetryIntervalMs: number;
|
||||
minimumSaveIntervalMs: number;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: SyncSettings = {
|
||||
|
|
@ -29,7 +28,6 @@ export const DEFAULT_SETTINGS: SyncSettings = {
|
|||
diffCacheSizeMB: 4,
|
||||
enableTelemetry: false,
|
||||
networkRetryIntervalMs: 1000,
|
||||
minimumSaveIntervalMs: 1000
|
||||
};
|
||||
|
||||
export class Settings {
|
||||
|
|
|
|||
|
|
@ -150,10 +150,6 @@ export class SyncClient {
|
|||
}
|
||||
);
|
||||
|
||||
const rateLimitedSave = rateLimit(
|
||||
persistence.save,
|
||||
() => settings.getSettings().minimumSaveIntervalMs
|
||||
);
|
||||
|
||||
const syncEventQueue = new SyncEventQueue(
|
||||
settings,
|
||||
|
|
@ -161,7 +157,7 @@ export class SyncClient {
|
|||
state.database,
|
||||
async (data): Promise<void> => {
|
||||
state = { ...state, database: data };
|
||||
await rateLimitedSave(state);
|
||||
await persistence.save(state);
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue