refactor(TorrentsRepository): Remove redundant implementation for filtering results

Filtering search results is now handled by SearchViewModel.

Signed-off-by: prajwalch <prajwal.chapagain58@gmail.com>
This commit is contained in:
prajwalch
2026-03-27 13:02:49 +05:45
parent 616ce72c53
commit 8c4ea8e60f
@@ -33,39 +33,19 @@ class TorrentsRepository @Inject constructor(
query = query,
category = category,
searchProviders = searchProviders,
).scan(SearchResults()) { searchResults, batchResult ->
processBatchResult(
currentSearchResults = searchResults,
batchResult = batchResult,
category = category,
)
}.flowOn(Dispatchers.IO)
).scan(
initial = SearchResults(),
operation = ::appendBatchResult,
).flowOn(Dispatchers.IO)
private fun processBatchResult(
private fun appendBatchResult(
currentSearchResults: SearchResults,
batchResult: Result<List<Torrent>>,
category: Category,
): SearchResults = batchResult.fold(
onSuccess = {
val newSuccesses = filterTorrentsByCategory(torrents = it, category = category)
currentSearchResults.appendSuccesses(newSuccesses)
},
onFailure = {
currentSearchResults.appendFailure(it as SearchException)
},
onSuccess = { currentSearchResults.appendSuccesses(it) },
onFailure = { currentSearchResults.appendFailure(it as SearchException) },
)
private fun filterTorrentsByCategory(
torrents: List<Torrent>,
category: Category,
): List<Torrent> {
return if (category == Category.All) {
torrents
} else {
torrents.filter { it.category == category }
}
}
suspend fun downloadTorrentFile(url: String): TorrentFileId {
val id = UUID.nameUUIDFromBytes(url.toByteArray())
if (torrentFileContentCache.containsKey(id)) return id