refactor: Improve duplicate request handling in checkDuplicateRequestAndStoreRequest function
This commit is contained in:
parent
a49cd49eee
commit
e66286662e
1 changed files with 6 additions and 3 deletions
|
|
@ -4,11 +4,12 @@ export function checkDuplicateRequestAndStoreRequest(config) {
|
|||
const lastUrl = localStorage.getItem("lastUrlCalled");
|
||||
const lastMethodCalled = localStorage.getItem("lastMethodCalled");
|
||||
const lastRequestTime = localStorage.getItem("lastRequestTime");
|
||||
const lastCurrentUrl = localStorage.getItem("lastCurrentUrl");
|
||||
|
||||
const currentUrl = window.location.pathname;
|
||||
const currentTime = Date.now();
|
||||
|
||||
const isContained = AUTHORIZED_DUPLICATE_REQUESTS.some((request) =>
|
||||
config?.url!.includes(request)
|
||||
config?.url!.includes(request),
|
||||
);
|
||||
|
||||
if (
|
||||
|
|
@ -17,7 +18,8 @@ export function checkDuplicateRequestAndStoreRequest(config) {
|
|||
lastMethodCalled === config.method &&
|
||||
lastMethodCalled === "get" && // Assuming you want to check only for GET requests
|
||||
lastRequestTime &&
|
||||
currentTime - parseInt(lastRequestTime, 10) < 800
|
||||
currentTime - parseInt(lastRequestTime, 10) < 300 &&
|
||||
lastCurrentUrl === currentUrl
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -25,6 +27,7 @@ export function checkDuplicateRequestAndStoreRequest(config) {
|
|||
localStorage.setItem("lastUrlCalled", config.url ?? "");
|
||||
localStorage.setItem("lastMethodCalled", config.method ?? "");
|
||||
localStorage.setItem("lastRequestTime", currentTime.toString());
|
||||
localStorage.setItem("lastCurrentUrl", currentUrl);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue