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

Query duplication #4604

Closed
ynkm169 opened this issue Jan 4, 2023 · 6 comments
Closed

Query duplication #4604

ynkm169 opened this issue Jan 4, 2023 · 6 comments

Comments

@ynkm169
Copy link

ynkm169 commented Jan 4, 2023

Version

3.7.0

Summary

Hello, when I click action button, network debugger shows 50 outgoing requests are sent to our server.
I noticed existing issue that was closed long time ago, not sure if things have changed. #646

    @Inject
    @AuthenticatedClient
    internal lateinit var apolloClient: ApolloClient

    private fun onActionButtonClicked() {
        for (i in 1..50) {
            disposables.add(
                apolloClient.query(
                    OffsiteQuery(
                        url = "https://thesassyowlboutique.com/products/hearts-aflutter-skort?variant=39947075715150"
                    )
                ).fetchPolicy(FetchPolicy.CacheFirst).rxSingle()
                // Ignore the result since this is just a prefetch
                .subscribe(Functions.emptyConsumer(), Functions.emptyConsumer())
            )
        }
    }

Screen Shot 2023-01-04 at 12 50 00 PM


Unrelated, with our REST Retrofit Repository implementation, it only fetches from server once.

@Inject
lateinit var urlInfoRepository: UrlInfoRepository

private fun onActionButtonClicked() {
    for (i in 1..50) {
        disposables.add(
            urlInfoRepository.getUrlInfo(
                "https://thesassyowlboutique" +
                    ".com/products/hearts-aflutter-skort?variant=39947075715150", "1059401512322041701", null
            )
            .subscribe(Functions.emptyConsumer(), Functions.emptyConsumer())
        )
    }
}
@BoD
Copy link
Contributor

BoD commented Jan 4, 2023

Hi!

There is no mechanism as of today to do this in Apollo Kotlin. Issue #646 is closed but issue #3760 can be used to track this.

Thanks for the heads up about Retrofit, I wasn't aware that it had such a mechanism, I'll have a look.
I am assuming this only works for GET though? I can imagine scenarios where you actually want to execute several identical POSTs on the same resource even if one is already ongoing. For GraphQL I think this would only be allowed to work on queries, not mutations.

@ynkm169
Copy link
Author

ynkm169 commented Jan 4, 2023

@BoD Hi Sorry for confusion, the dedup mechanism is from our own Repository implementation, not Retrofit. Basically we cache a Map<request, Observable>. If our code calls Repository.get(url) multiple times with same url, the map will retrieve the same observable.

@BoD
Copy link
Contributor

BoD commented Jan 4, 2023

Ooh right! Thanks for clarifying. I guess this could also work on top of Apollo?

@ynkm169
Copy link
Author

ynkm169 commented Jan 4, 2023 via email

@BoD
Copy link
Contributor

BoD commented Jan 5, 2023

Thanks for clarifying! Is it ok to close this ticket in favor of #3760?

@ynkm169
Copy link
Author

ynkm169 commented Jan 5, 2023

For sure thank you!

@ynkm169 ynkm169 closed this as completed Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants