1
0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2026-03-03 16:49:20 +00:00

Add request quota system

This commit is contained in:
Cadence Ember
2020-07-23 00:58:21 +12:00
parent 2095be2742
commit 112d9cc90e
17 changed files with 253 additions and 38 deletions

View File

@@ -45,16 +45,22 @@ class Timeline {
: this.type === "igtv" ? collectors.fetchIGTVPage
: null
const after = this.page_info ? this.page_info.end_cursor : ""
return method(this.user.data.id, after).then(page => {
return method(this.user.data.id, after).then(({result: page, fromCache}) => {
const quotaUsed = fromCache ? 0 : 1
this.addPage(page)
return this.pages.slice(-1)[0]
return {page: this.pages.slice(-1)[0], quotaUsed}
})
}
async fetchUpToPage(index) {
let quotaUsed = 0
while (this.pages[index] === undefined && this.hasNextPage()) {
await this.fetchNextPage()
const result = await this.fetchNextPage()
if (typeof result !== "symbol") {
quotaUsed += result.quotaUsed
}
}
return quotaUsed
}
addPage(page) {

View File

@@ -32,7 +32,7 @@ class TimelineEntry extends TimelineBaseMethods {
async update() {
return collectors.fetchShortcodeData(this.data.shortcode).then(data => {
this.applyN3(data)
this.applyN3(data.result)
}).catch(error => {
console.error("TimelineEntry could not self-update; trying to continue anyway...")
console.error("E:", error)