feat: properly fetch all settings from server (#5177)

This commit is contained in:
Aviad Pineles 2023-09-21 21:18:01 +03:00 committed by GitHub
parent 5c050091be
commit ed20c855d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 9 deletions

View File

@ -150,16 +150,31 @@ export async function getSettings(): Promise<void> {
const db = database.active;
const settingsParams = Object.keys(defaultSettings).filter(key => !loginSettings.includes(key));
// RC 0.60.0
const result = await fetch(
`${sdk.current.client.host}/api/v1/settings.public?query={"_id":{"$in":${JSON.stringify(settingsParams)}}}&count=${
settingsParams.length
}`
).then(response => response.json());
let offset = 0;
let remaining;
let settings: IData[] = [];
// Iterate over paginated results to retrieve all settings
do {
// TODO: why is no-await-in-loop enforced in the first place?
/* eslint-disable no-await-in-loop */
const response = await fetch(
`${sdk.current.client.host}/api/v1/settings.public?query={"_id":{"$in":${JSON.stringify(settingsParams)}}}
&offset=${offset}`);
const result = await response.json();
if (!result.success) {
return;
}
const data: IData[] = result.settings || [];
offset += result.settings.length;
settings = [...settings, ...result.settings];
remaining = result.total - settings.length;
/* eslint-enable no-await-in-loop */
} while(remaining > 0);
const data: IData[] = settings;
const filteredSettings: IPreparedSettings[] = _prepareSettings(data);
const filteredSettingsIds = filteredSettings.map(s => s._id);
const parsedSettings = parseSettings(filteredSettings);