Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: OPTIC-1418: Improve Organization Membership API usage to reduce latency #6780

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
yyassi-heartex marked this conversation as resolved.
Show resolved Hide resolved

return responseResult;
};
}
Expand Down
Loading