Skip to content

Commit

Permalink
refactor(greader): incrementally fetch the starred and read items
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashinch committed Jan 22, 2024
1 parent 2361375 commit aff7aff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ class GoogleReaderRssService @Inject constructor(
val googleReaderAPI = getGoogleReaderAPI()
val groupIds = mutableSetOf<String>()
val feedIds = mutableSetOf<String>()
val lastUpdateAt = Calendar.getInstance().apply {
if (account.updateAt != null) {
time = account.updateAt!!
add(Calendar.HOUR, -1)
} else {
time = Date()
add(Calendar.MONTH, -1)
}
}.time.time / 1000

// 1. Fetch list of feeds and folders
googleReaderAPI.getSubscriptionList()
Expand Down Expand Up @@ -264,17 +273,12 @@ class GoogleReaderRssService @Inject constructor(
fetchItemsContents(unreadItems, googleReaderAPI, accountId, feedIds, unreadIds, listOf())

// 4. Fetch ids of starred items
val starredItems = googleReaderAPI.getStarredItemIds().itemRefs
val starredItems = googleReaderAPI.getStarredItemIds(lastUpdateAt).itemRefs
val starredIds = starredItems?.map { it.id }
fetchItemsContents(starredItems, googleReaderAPI, accountId, feedIds, unreadIds, starredIds)

// 5. Fetch ids of read items since last month
val readItems = googleReaderAPI.getReadItemIds(
Calendar.getInstance().apply {
time = Date()
add(Calendar.MONTH, -1)
}.time.time / 1000
).itemRefs
val readItems = googleReaderAPI.getReadItemIds(lastUpdateAt).itemRefs

// 6. Fetch items contents for ids
fetchItemsContents(readItems, googleReaderAPI, accountId, feedIds, unreadIds, starredIds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,22 +200,26 @@ class GoogleReaderAPI private constructor(
Pair("n", MAXIMUM_ITEMS_LIMIT),
))

suspend fun getUnreadItemIds(): GoogleReaderDTO.ItemIds =
suspend fun getUnreadItemIds(since: Long? = null): GoogleReaderDTO.ItemIds =
retryableGetRequest<GoogleReaderDTO.ItemIds>(
query = "reader/api/0/stream/items/ids",
params = listOf(
Pair("s", Stream.ALL_ITEMS.tag),
Pair("xt", Stream.READ.tag),
Pair("n", MAXIMUM_ITEMS_LIMIT),
))
params = mutableListOf<Pair<String, String>>().apply {
add(Pair("s", Stream.ALL_ITEMS.tag))
add(Pair("xt", Stream.READ.tag))
add(Pair("n", MAXIMUM_ITEMS_LIMIT))
since?.let { add(Pair("ot", since.toString())) }
}
)

suspend fun getStarredItemIds(): GoogleReaderDTO.ItemIds =
suspend fun getStarredItemIds(since: Long? = null): GoogleReaderDTO.ItemIds =
retryableGetRequest<GoogleReaderDTO.ItemIds>(
query = "reader/api/0/stream/items/ids",
params = listOf(
Pair("s", Stream.STARRED.tag),
Pair("n", MAXIMUM_ITEMS_LIMIT),
))
params = mutableListOf<Pair<String, String>>().apply {
add(Pair("s", Stream.STARRED.tag))
add(Pair("n", MAXIMUM_ITEMS_LIMIT))
since?.let { add(Pair("ot", since.toString())) }
}
)

suspend fun getItemsContents(ids: List<String>?) =
retryablePostRequest<GoogleReaderDTO.ItemsContents>(
Expand Down

0 comments on commit aff7aff

Please sign in to comment.