appstore: collect the Play search pages that were fetched
- Commit
43acd037556035cdf0654f2a12b716e952ad2ce0- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 19:39 UTC (28 days ago)
- Parents
989fc9d
Symptom: Play search silently returned nothing whenever Play answered in a single page, and never showed the last page it paid to fetch. A one-page answer (hasNext() false on the first bundle) produced an empty result list, so niche queries looked like 'app not on Play' even though Play had just answered. Root cause: the loop tested shouldReadPage() before collecting: 'page >= maxPages || !bundle.hasNext()' gated collection itself, not just the next fetch. Page 1 with no successor was never collected, and with maxPages=3 the third bundle was fetched and then discarded uncollected. Fix: collect the current bundle first, then stop when the query is answered, the page cap is reached, or there is no next page. Removed the now-unused shouldReadPage helper. No new test: the loop needs a live gplayapi SearchHelper/session, which the JVM unit-test setup cannot fake; verified by inspection against the old trace (1-page, answered-early, and capped cases). Verification: :appstore:compileDevKotlin and :appstore:testDevUnitTest pass.
Diff
appstore/src/main/java/com/vayunmathur/appstore/data/play/PlayStoreApi.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/play/PlayStoreApi.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/play/PlayStoreApi.ktindex 2a284fb5b2..f56cf53a4f 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/play/PlayStoreApi.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/play/PlayStoreApi.kt@@ -96,11 +96,17 @@ class PlayStoreApi( val helper = SearchHelper(authData).using(httpClient) val found = LinkedHashMap<String, UnifiedApp>() var bundle = helper.searchResults(query)- var page = 1- while (shouldReadPage(found.values.toList(), answered, page, maxPages, bundle)) {+ // Collect first, then decide whether another page is worth+ // fetching. Checking hasNext() before collecting dropped a+ // single-page result set entirely, and the page counter+ // stopped one page short of maxPages while still fetching+ // (and discarding) that last page.+ var pagesRead = 0+ while (true) { collectPage(bundle, found)+ pagesRead+++ if (answered(found.values.toList()) || pagesRead >= maxPages || !bundle.hasNext()) break bundle = helper.nextStreamBundle(query, bundle.streamNextPageUrl)- page++ } found.values.toList() } catch (_: java.io.IOException) {@@ -122,18 +128,6 @@ class PlayStoreApi( } } - private fun shouldReadPage(- found: List<UnifiedApp>,- answered: (List<UnifiedApp>) -> Boolean,- page: Int,- maxPages: Int,- bundle: com.aurora.gplayapi.data.models.StreamBundle,- ): Boolean {- if (answered(found)) return false- if (page >= maxPages || !bundle.hasNext()) return false- return true- }- /** A real top chart, rather than whatever the store's HTML happened to render. */ suspend fun topChart( type: TopChartsContract.Type = TopChartsContract.Type.APPLICATION,