import { API } from 'api' export class Sync { constructor() { this.foo = '' } static async tree() { try { const state = await nodeStore.getAppState('latest_sync') const oldMax = (state?.value ? state.value : 0) let newMax = 0 let offset = 0 let res = { Continue: false } let batch = 0 do { batch++ console.log(`Batch #${batch}`) res = await API.query('POST', `/node/tree/${oldMax}/${offset}`, {}) offset += res.Nodes.length newMax = res.MaxSeq await nodeStore.upsertTreeRecords(res.Nodes) } while (res.Continue) nodeStore.setAppState('latest_sync', Math.max(oldMax, newMax)) } catch (e) { console.log('sync node tree', e) } } }