MCPcopy Create free account
hub / github.com/codecombat/codecombat / fetchBatch

Method fetchBatch

app/views/admin/SchoolCountsView.js:51–69  ·  view source on GitHub ↗
(baseUrl, results, beforeId)

Source from the content-addressed store, hash-verified

49
50 loadData () {
51 var fetchBatch = (baseUrl, results, beforeId) => {
52 let url = `${baseUrl}?options[limit]=${this.batchSize}`
53 if (beforeId) { url += `&options[beforeId]=${beforeId}` }
54 return new Promise(resolve => setTimeout(resolve.bind(null, Promise.resolve($.get(url))), 200))
55 .then(batchResults => {
56 if (this.destroyed) { return Promise.resolve([]) }
57 results = results.concat(batchResults)
58 if (batchResults.length < this.batchSize) {
59 this.updateLoadingState(`Received ${results.length} from ${baseUrl} TOTAL`)
60 return Promise.resolve(results)
61 } else {
62 this.updateLoadingState(`Received ${results.length} from ${baseUrl} so far`)
63 return fetchBatch(baseUrl, results, batchResults[batchResults.length - 1]._id)
64 }
65 }).catch(error => {
66 console.log(new Date().toISOString(), `ERROR! Trying ${baseUrl} ${beforeId} again`, error.status, error.statusText)
67 return fetchBatch(baseUrl, results, beforeId)
68 })
69 }
70
71 return Promise.all([
72 fetchBatch('/db/classroom/-/users', []),

Callers

nothing calls this directly

Calls 3

updateLoadingStateMethod · 0.95
logMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected