Skip to content

Commit

Permalink
Fetch missing articles
Browse files Browse the repository at this point in the history
  • Loading branch information
jocmp committed Nov 3, 2024
1 parent 02415ae commit bba5513
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ internal class FeedbinAccountDelegate(
coroutineScope {
ids.chunked(MAX_ENTRY_LIMIT).map { chunkedIDs ->
launch {
fetchPaginatedEntries(ids = chunkedIDs)
fetchPaginatedEntries(ids = chunkedIDs.map { it.toLong() })
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import com.jocmp.readerclient.GoogleReader
import com.jocmp.readerclient.Item
import com.jocmp.readerclient.Stream
import com.jocmp.readerclient.Subscription
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import org.jsoup.Jsoup
import java.io.IOException
Expand Down Expand Up @@ -163,7 +165,18 @@ internal class ReaderAccountDelegate(
}


private fun fetchMissingArticles() {
private suspend fun fetchMissingArticles() {
val ids = articleRecords.findMissingArticles()

coroutineScope {
ids.chunked(MAX_ITEM_LIMIT).map { chunkedIDs ->
launch {
withResult(googleReader.streamItemsContents(chunkedIDs)) { result ->
saveItems(result.items)
}
}
}
}
}

private suspend fun refreshAllArticles(since: Long) {
Expand Down Expand Up @@ -227,4 +240,9 @@ internal class ReaderAccountDelegate(
private fun taggingID(subscription: Subscription, category: Category): String {
return "${subscription.id}:${category.id}"
}


companion object {
const val MAX_ITEM_LIMIT = 100
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ internal class ArticleRecords internal constructor(
).executeAsOneOrNull()
}

fun findMissingArticles(): List<Long> {
fun findMissingArticles(): List<String> {
return database
.articlesQueries
.findMissingArticles()
.executeAsList()
.map { it.toLong() }
}

internal suspend fun notifications(since: ZonedDateTime): List<ArticleNotification> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory
import retrofit2.create
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
Expand All @@ -20,17 +22,18 @@ interface GoogleReader {

@GET("reader/api/0/stream/items/ids")
suspend fun streamItemsIDs(
@Query("s") streamID: String,
@Query("n") count: Int = 10_000,
@Query("xt") excludedStreamID: String? = null,
@Query("output") output: String = "json",
@Query("s") streamID: String,
@Query("n") count: Int = 10_000,
@Query("xt") excludedStreamID: String? = null,
@Query("output") output: String = "json",
): Response<StreamItemIDsResult>

// use to fetch missing articles
@FormUrlEncoded
@POST("reader/api/0/stream/items/contents")
suspend fun streamItemsContents(
// @FormUrlEncoded
)
@Field("i") ids: List<String>
): Response<StreamItemsContentsResult>

@GET("reader/api/0/stream/contents/{streamID}")
suspend fun streamContents(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.jocmp.readerclient

import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class StreamItemsContentsResult(
val items: List<Item>,
)

0 comments on commit bba5513

Please sign in to comment.