@@ -44,15 +44,16 @@ import kotlin.time.ExperimentalTime
4444
4545class HomeRepositoryImpl (
4646 private val httpClient : HttpClient ,
47- private val platform : Platform ,
47+ private val devicePlatform : Platform ,
4848 private val cachedDataSource : CachedRepositoriesDataSource ,
4949 private val logger : GitHubStoreLogger ,
5050 private val cacheManager : CacheManager ,
5151) : HomeRepository {
5252 private fun cacheKey (
5353 category : String ,
54+ requestedPlatform : HomePlatform ,
5455 page : Int ,
55- ): String = " home:$category :${platform .name} :page$page "
56+ ): String = " home:$category :${requestedPlatform .name} :page$page "
5657
5758 @OptIn(ExperimentalTime ::class )
5859 override fun getTrendingRepositories (
@@ -76,15 +77,31 @@ class HomeRepositoryImpl(
7677 hasMore = false ,
7778 nextPageIndex = 2 ,
7879 )
79- cacheManager.put(cacheKey(" trending" , page), result, CacheManager .CacheTtl .HOME_REPOS )
80+ cacheManager.put(
81+ key =
82+ cacheKey(
83+ category = " trending" ,
84+ requestedPlatform = platform,
85+ page = page,
86+ ),
87+ value = result,
88+ ttlMillis = HOME_REPOS ,
89+ )
8090 emit(result)
8191 return @flow
8292 } else {
8393 logger.debug(" No mirror data, checking local cache..." )
8494 }
8595 }
8696
87- val localCached = cacheManager.get<PaginatedDiscoveryRepositories >(cacheKey(" trending" , page))
97+ val localCached =
98+ cacheManager.get<PaginatedDiscoveryRepositories >(
99+ cacheKey(
100+ category = " trending" ,
101+ requestedPlatform = platform,
102+ page = page,
103+ ),
104+ )
88105 if (localCached != null && localCached.repos.isNotEmpty()) {
89106 logger.debug(" Using locally cached trending repos: ${localCached.repos.size} " )
90107 emit(localCached)
@@ -100,6 +117,7 @@ class HomeRepositoryImpl(
100117
101118 emitAll(
102119 searchReposWithInstallersFlow(
120+ platform = platform,
103121 baseQuery = " stars:>50 archived:false pushed:>=$thirtyDaysAgo " ,
104122 sort = " stars" ,
105123 order = " desc" ,
@@ -131,15 +149,31 @@ class HomeRepositoryImpl(
131149 hasMore = false ,
132150 nextPageIndex = 2 ,
133151 )
134- cacheManager.put(cacheKey(" hot_release" , page), result, CacheManager .HOME_REPOS )
152+ cacheManager.put(
153+ key =
154+ cacheKey(
155+ category = " hot_release" ,
156+ requestedPlatform = platform,
157+ page = page,
158+ ),
159+ value = result,
160+ ttlMillis = HOME_REPOS ,
161+ )
135162 emit(result)
136163 return @flow
137164 } else {
138165 logger.debug(" No mirror data, checking local cache..." )
139166 }
140167 }
141168
142- val localCached = cacheManager.get<PaginatedDiscoveryRepositories >(cacheKey(" hot_release" , page))
169+ val localCached =
170+ cacheManager.get<PaginatedDiscoveryRepositories >(
171+ cacheKey(
172+ category = " hot_release" ,
173+ requestedPlatform = platform,
174+ page = page,
175+ ),
176+ )
143177 if (localCached != null && localCached.repos.isNotEmpty()) {
144178 logger.debug(" Using locally cached hot release repos: ${localCached.repos.size} " )
145179 emit(localCached)
@@ -155,6 +189,7 @@ class HomeRepositoryImpl(
155189
156190 emitAll(
157191 searchReposWithInstallersFlow(
192+ platform = platform,
158193 baseQuery = " stars:>10 archived:false pushed:>=$fourteenDaysAgo " ,
159194 sort = " updated" ,
160195 order = " desc" ,
@@ -186,15 +221,22 @@ class HomeRepositoryImpl(
186221 hasMore = false ,
187222 nextPageIndex = 2 ,
188223 )
189- cacheManager.put(cacheKey(" most_popular" , page), result, HOME_REPOS )
224+ cacheManager.put(cacheKey(" most_popular" , platform, page), result, HOME_REPOS )
190225 emit(result)
191226 return @flow
192227 } else {
193228 logger.debug(" No mirror data, checking local cache..." )
194229 }
195230 }
196231
197- val localCached = cacheManager.get<PaginatedDiscoveryRepositories >(cacheKey(" most_popular" , page))
232+ val localCached =
233+ cacheManager.get<PaginatedDiscoveryRepositories >(
234+ cacheKey(
235+ category = " most_popular" ,
236+ requestedPlatform = platform,
237+ page = page,
238+ ),
239+ )
198240 if (localCached != null && localCached.repos.isNotEmpty()) {
199241 logger.debug(" Using locally cached most popular repos: ${localCached.repos.size} " )
200242 emit(localCached)
@@ -217,6 +259,7 @@ class HomeRepositoryImpl(
217259
218260 emitAll(
219261 searchReposWithInstallersFlow(
262+ platform = platform,
220263 baseQuery = " stars:>1000 archived:false created:<$sixMonthsAgo pushed:>=$oneYearAgo " ,
221264 sort = " stars" ,
222265 order = " desc" ,
@@ -227,6 +270,7 @@ class HomeRepositoryImpl(
227270 }.flowOn(Dispatchers .IO )
228271
229272 private fun searchReposWithInstallersFlow (
273+ platform : HomePlatform ,
230274 baseQuery : String ,
231275 sort : String ,
232276 order : String ,
@@ -243,7 +287,7 @@ class HomeRepositoryImpl(
243287 var pagesFetchedCount = 0
244288 var lastEmittedCount = 0
245289
246- val query = buildSimplifiedQuery(baseQuery)
290+ val query = buildSimplifiedQuery(baseQuery, platform )
247291 logger.debug(" Query: $query | Sort: $sort | Page: $startPage " )
248292
249293 while (results.size < desiredCount && pagesFetchedCount < maxPagesToFetch) {
@@ -346,7 +390,8 @@ class HomeRepositoryImpl(
346390
347391 if (results.size > lastEmittedCount) {
348392 val finalBatch = results.subList(lastEmittedCount, results.size)
349- val finalHasMore = pagesFetchedCount < maxPagesToFetch && results.size >= desiredCount
393+ val finalHasMore =
394+ pagesFetchedCount < maxPagesToFetch && results.size >= desiredCount
350395 val finalResult =
351396 PaginatedDiscoveryRepositories (
352397 repos = finalBatch.toList(),
@@ -373,21 +418,34 @@ class HomeRepositoryImpl(
373418 hasMore = pagesFetchedCount < maxPagesToFetch && results.size >= desiredCount,
374419 nextPageIndex = currentApiPage + 1 ,
375420 )
376- cacheManager.put(cacheKey(category, startPage), allResults, HOME_REPOS )
421+ cacheManager.put(
422+ key =
423+ cacheKey(
424+ category = category,
425+ requestedPlatform = platform,
426+ page = startPage,
427+ ),
428+ value = allResults,
429+ ttlMillis = HOME_REPOS ,
430+ )
377431 logger.debug(" Cached ${results.size} repos for $category page $startPage " )
378432 }
379433 }.flowOn(Dispatchers .IO )
380434
381- private fun buildSimplifiedQuery (baseQuery : String ): String {
435+ private fun buildSimplifiedQuery (
436+ baseQuery : String ,
437+ requestedPlatform : HomePlatform ,
438+ ): String {
382439 val topic =
383- when (platform) {
384- Platform .ANDROID -> " android"
385- Platform .WINDOWS -> " desktop"
386- Platform .MACOS -> " macos"
387- Platform .LINUX -> " linux"
440+ when (requestedPlatform) {
441+ HomePlatform .All -> null
442+ HomePlatform .Android -> " android"
443+ HomePlatform .Windows -> " desktop"
444+ HomePlatform .Macos -> " macos"
445+ HomePlatform .Linux -> " linux"
388446 }
389447
390- return " $baseQuery topic:$topic "
448+ return if (topic == null ) baseQuery else " $baseQuery topic:$topic "
391449 }
392450
393451 private fun calculatePlatformScore (repo : GithubRepoNetworkModel ): Int {
@@ -396,7 +454,7 @@ class HomeRepositoryImpl(
396454 val language = repo.language?.lowercase()
397455 val desc = repo.description?.lowercase() ? : " "
398456
399- when (platform ) {
457+ when (devicePlatform ) {
400458 Platform .ANDROID -> {
401459 if (topics.contains(" android" )) score + = 10
402460 if (topics.contains(" mobile" )) score + = 5
@@ -450,7 +508,7 @@ class HomeRepositoryImpl(
450508 val relevantAssets =
451509 stableRelease.assets.filter { asset ->
452510 val name = asset.name.lowercase()
453- when (platform ) {
511+ when (devicePlatform ) {
454512 Platform .ANDROID -> {
455513 name.endsWith(" .apk" )
456514 }
0 commit comments