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

Function processAllBatches

app/core/store/modules/levelSessions.js:141–176  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

139 const totalRequests = parseInt(classroom.members.length / SESSIONS_PER_REQUEST, 10) + 1
140
141 const processAllBatches = async () => {
142 let allSessions = []
143 let lastUpdatedAt = null
144
145 for (let i = 0; i < totalRequests; i += BATCH_SIZE) {
146 const batchEnd = Math.min(i + BATCH_SIZE, totalRequests)
147 const batchRequests = []
148
149 for (let j = i; j < batchEnd; j++) {
150 batchRequests.push(
151 levelSessionsApi.fetchForClassroomMembers(classroom._id, {
152 data: {
153 memberLimit: SESSIONS_PER_REQUEST,
154 memberSkip: j * SESSIONS_PER_REQUEST,
155 project: options.project || 'state.complete,level,creator,changed,created,dateFirstCompleted,submitted,codeConcepts'
156 }
157 })
158 )
159 }
160
161 const batchResults = await Promise.all(batchRequests)
162
163 for (const res of batchResults) {
164 if (res && Array.isArray(res.sessions)) {
165 allSessions = allSessions.concat(res.sessions)
166 if (res.lastUpdatedAt) {
167 lastUpdatedAt = res.lastUpdatedAt
168 }
169 } else {
170 throw new Error('Unexpected response from level sessions call')
171 }
172 }
173 }
174
175 return { sessions: allSessions, lastUpdatedAt }
176 }
177
178 return processAllBatches()
179 .then(({ sessions, lastUpdatedAt }) => {

Callers 1

levelSessions.jsFile · 0.85

Calls 1

Tested by

no test coverage detected