Fix/properly reset cache and queues on server url change and backup import (#725)
* Reset cache on server url change * Reset image queue * Completely reset apollo store
This commit is contained in:
@@ -34,6 +34,16 @@ export class Queue {
|
|||||||
this.queue = pLimit(concurrency);
|
this.queue = pLimit(concurrency);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear(): void {
|
||||||
|
this.pendingKeyToPromiseMap.forEach((promise) => {
|
||||||
|
promise.reject(new Error('Queue::clear: called'));
|
||||||
|
});
|
||||||
|
|
||||||
|
this.pendingKeyToPriorityMap.clear();
|
||||||
|
this.pendingKeyToFnMap.clear();
|
||||||
|
this.pendingKeyToPromiseMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
enqueue<T>(key: Key, fn: () => PromiseLike<T> | T, priority: QueuePriority = Priority.NORMAL): Promise<T> {
|
enqueue<T>(key: Key, fn: () => PromiseLike<T> | T, priority: QueuePriority = Priority.NORMAL): Promise<T> {
|
||||||
this.counter = (this.counter + 1) % Infinity;
|
this.counter = (this.counter + 1) % Infinity;
|
||||||
const actualKey = `${key}_${this.counter}`;
|
const actualKey = `${key}_${this.counter}`;
|
||||||
|
|||||||
@@ -409,6 +409,12 @@ export class RequestManager {
|
|||||||
this.graphQLClient.updateConfig();
|
this.graphQLClient.updateConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public reset(): void {
|
||||||
|
this.graphQLClient.client.resetStore();
|
||||||
|
this.cache.clear();
|
||||||
|
this.imageQueue.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public getBaseUrl(): string {
|
public getBaseUrl(): string {
|
||||||
return this.restClient.getBaseUrl();
|
return this.restClient.getBaseUrl();
|
||||||
}
|
}
|
||||||
@@ -2143,8 +2149,7 @@ export class RequestManager {
|
|||||||
);
|
);
|
||||||
|
|
||||||
result.response.then(() => {
|
result.response.then(() => {
|
||||||
this.graphQLClient.client.cache.reset();
|
this.reset();
|
||||||
this.cache.clear();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ export const ServerSettings = () => {
|
|||||||
const handleServerAddressChange = (address: string) => {
|
const handleServerAddressChange = (address: string) => {
|
||||||
const serverBaseUrl = address.replaceAll(/(\/)+$/g, '');
|
const serverBaseUrl = address.replaceAll(/(\/)+$/g, '');
|
||||||
setServerAddress(serverBaseUrl);
|
setServerAddress(serverBaseUrl);
|
||||||
|
requestManager.reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateSetting = <Setting extends keyof ServerSettingsType>(
|
const updateSetting = <Setting extends keyof ServerSettingsType>(
|
||||||
|
|||||||
Reference in New Issue
Block a user