Skip to content

Commit

Permalink
fix: OPTIC-1418: Improve Organization Membership API usage to reduce …
Browse files Browse the repository at this point in the history
…latency (#6780)
  • Loading branch information
bmartel authored Dec 16, 2024
1 parent 1ac41ae commit ca1da7a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion web/libs/datamanager/src/stores/AppStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ export const AppStore = types
}),

fetchUsers: flow(function* () {
const list = yield self.apiCall("users");
const list = yield self.apiCall("users", { __useQueryCache: 60 * 1000 });

self.users.push(...list);
}),
Expand Down
25 changes: 24 additions & 1 deletion web/libs/datamanager/src/utils/api-proxy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,26 @@ export class APIProxy {
let responseMeta;
const alwaysExpectJSON = options?.alwaysExpectJSON === undefined ? true : options.alwaysExpectJSON;

let shouldUseQueryCache = false;
try {
const finalParams = {
...(methodSettings.params ?? {}),
...(urlParams ?? {}),
...(this.sharedParams ?? {}),
};

if (finalParams.__useQueryCache && methodSettings.queryCache) {
shouldUseQueryCache = true;

const cachedData = methodSettings.queryCache(finalParams);

if (cachedData) {
return cachedData;
}

delete finalParams.__useQueryCache;
}

const { method, url: apiCallURL } = this.createUrl(
methodSettings.path,
finalParams,
Expand Down Expand Up @@ -247,7 +260,13 @@ export class APIProxy {
: { ok: true };

if (methodSettings.convert instanceof Function) {
return await methodSettings.convert(responseData);
const convertedData = await methodSettings.convert(responseData);

if (shouldUseQueryCache) {
methodSettings.queryCache(finalParams, convertedData);
}

return convertedData;
}

responseResult = responseData;
Expand All @@ -268,6 +287,10 @@ export class APIProxy {
writable: false,
});

if (shouldUseQueryCache) {
methodSettings.queryCache(finalParams, responseResult);
}

return responseResult;
};
}
Expand Down

0 comments on commit ca1da7a

Please sign in to comment.