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

Cancel Request if same request called subsequently multiple times is keeping active request too long to get response, Please Help. #2934

Closed
kathirr007 opened this issue Apr 29, 2020 · 1 comment

Comments

@kathirr007
Copy link

kathirr007 commented Apr 29, 2020

Issue Description

I'm trying infinite scrolling for list of data fetching from an API. On some condition the same api call is being called multiple times subsequently. I've tried to cancel the multiple axios calls using Cancel API in axios. The requests are getting cancelled, but the one active request taking too long time to response.
The following is the scenario about timing issue i am facing for ex:

  • The first api call takes the time of about 5.40s
  • The next active api call after canceling one time takes 10.57s
  • The next active api call after canceling two times takes 15.90s
  • The next active api call after canceling three times takes 21.12s
  • The next active api call after canceling four times takes 25.96s

Please help me to reduce the active api call timing.

Thanks in advance.

Issue Code

Here is the Code I've used to test the axios cancellation. For security reason the API URL is changed.

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.2/axios.min.js"></script>

    <title>Document</title>
</head>

<body>
    <div id="app">
        <button @click="getMissions">Get Missions</button>
    </div>
    <script>
        new Vue({
            el: "#app",
            data: {
                axiosCall : null,
            },
            methods: {
                getMissions() {
                    // let
                    // debugger
                    let url = "http://xxx.x1.fr/xxx?client_secret=xxx&startFrom=0&numberOfRecords=5"
                    if(this.axiosCall != null) {
                        // debugger
                        this.axiosCall.cancel();
                        // console.log('request canceled...')
                    }
                    this.axiosCall = axios.CancelToken.source();
                    axios.get(url, { cancelToken: this.axiosCall.token })
                    .then((response) => {
                        console.log(response.data)
                    })
                    .catch(function(thrown) {
                        if (axios.isCancel(thrown)) {
                            console.log('API request is canceled...', thrown.message);
                        } else {
                            // handle error
                        }
                    });
                }
            }
        })
    </script>
</body>

</html>

Expected behavior, if applicable
The active API call should take same timing as the first API call even after cancelling subsequent API calls.

Environment:

  • Axios Version: 0.19.2
  • OS: Windows 10 Pro
  • Browser: Chrome
  • Browser Version: 81
  • Additional Library Versions Vuejs 2.6.11

Screenshots
axios-cancel-request-test

@jasonsaayman
Copy link
Member

Hi @kathirr007,

This seems to be a performance based and seems to have to do with the server that you are calling. I would suggest looking at the back end.

Thanks

@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants