Accelerar listado ventas
This commit is contained in:
@ -116,10 +116,15 @@
|
||||
this.data.id = data.proyecto.id
|
||||
this.data.proyecto = data.proyecto.descripcion
|
||||
this.data.venta_ids = data.ventas
|
||||
const chunkSize = 50
|
||||
const chunks = []
|
||||
for (let i = 0; i < data.ventas.length; i += chunkSize) {
|
||||
chunks.push(data.ventas.splice(i, i + chunkSize))
|
||||
}
|
||||
const promises = []
|
||||
data.ventas.forEach(venta_id => {
|
||||
const promise = this.get().venta(venta_id).then(() => {
|
||||
progress.progress('increment')
|
||||
chunks.forEach(chunk => {
|
||||
const promise = this.get().venta(chunk).then(count => {
|
||||
progress.progress('increment', count)
|
||||
})
|
||||
promises.push(promise)
|
||||
})
|
||||
@ -129,17 +134,22 @@
|
||||
}
|
||||
})
|
||||
},
|
||||
venta: venta_id => {
|
||||
return fetchAPI('{{$urls->api}}/venta/' + venta_id).then(response => {
|
||||
venta: chunk => {
|
||||
const body = new FormData()
|
||||
body.set('ventas', chunk.join(','))
|
||||
return fetchAPI('{{$urls->api}}/ventas/get', {method: 'post', body}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
if (typeof data.venta === 'undefined') {
|
||||
console.error(venta_id, data.error)
|
||||
if (data.ventas.length === 0) {
|
||||
console.error(chunk, data.error)
|
||||
return
|
||||
}
|
||||
this.add().venta(data.venta)
|
||||
data.ventas.forEach(venta_id => {
|
||||
this.add().venta(venta_id)
|
||||
})
|
||||
return data.ventas.length
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user