Skip to content

Commit f6b8146

Browse files
committed
Fix rates server bookmarking
1 parent 057fbda commit f6b8146

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/ratesEngine.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,27 @@ export async function ratesEngine(): Promise<void> {
4848
limit: QUERY_LIMIT
4949
}
5050
]
51-
let bookmark
51+
const bookmarks: Array<string | undefined> = []
5252
let count = 1
5353
while (true) {
5454
count++
5555
datelog('Querying missing rates')
5656
const result2 = await dbSettings.get('currencyCodeMappings')
5757
const { mappings } = asDbCurrencyCodeMappings(result2)
5858

59-
const query = queries[count % 2]
60-
query.bookmark = bookmark
59+
const index = count % 2
60+
61+
const query = queries[index]
62+
query.bookmark = bookmarks[index]
6163

6264
const result = await dbTransactions.find(query)
6365
if (
6466
typeof result.bookmark === 'string' &&
6567
result.docs.length === QUERY_LIMIT
6668
) {
67-
bookmark = result.bookmark
69+
bookmarks[index] = result.bookmark
6870
} else {
69-
bookmark = undefined
71+
bookmarks[index] = undefined
7072
}
7173
try {
7274
asDbQueryResult(result)
@@ -101,11 +103,11 @@ export async function ratesEngine(): Promise<void> {
101103
} catch (e) {
102104
datelog('Error doing bulk usdValue insert', e)
103105
}
104-
if (bookmark == null) {
106+
if (bookmarks[index] == null) {
105107
datelog(`Snoozing for ${QUERY_FREQ_MS} milliseconds`)
106108
await snooze(QUERY_FREQ_MS)
107109
} else {
108-
datelog(`Fetching bookmark ${bookmark}`)
110+
datelog(`Fetching bookmark ${bookmarks[index]}`)
109111
}
110112
}
111113
}

0 commit comments

Comments
 (0)