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: stop simultaneous recursive chains #225

Merged
merged 1 commit into from
Apr 21, 2021

Conversation

Jwhiles
Copy link
Contributor

@Jwhiles Jwhiles commented Apr 19, 2021

Sometimes the calls made in shopify can take a long time to resolve. Because of the way the pagination code is structured, this could lead to there being multiple recursive chains of calls for the function fetchNext happening simultaneously. Each time the function is invoked we checked whether the search term had changed, and if so, assumed that this was a new search term and that we should start fetching from scratch. If two requests became active at once, they would both repeatedly reset, as with each call it would be appear that the search term had changed.

@Jwhiles Jwhiles requested a review from shikaan April 19, 2021 13:53
Copy link
Contributor

@shikaan shikaan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No red flags. Just one minor comment which makes - to me - the code easier to reason about

@@ -25,8 +25,13 @@ class Pagination {
this.shopifyClient = await makeShopifyClient(this.sdk);
}

async fetchNext(search) {
async fetchNext(search, recursing = false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really a fan of arbitrary flags, but that might be me. What about interrupting recursion before entering the new call? So just before the return of this method (L63 in the new version, L58 of the old one)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. I think that makes it more likely that we'll be returning data from a dead chain - and I think would make this change a lot more complicated.

@Jwhiles Jwhiles merged commit 0433a5d into master Apr 21, 2021
@Jwhiles Jwhiles deleted the fix-stop-multiple-recursive-functions branch April 21, 2021 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants