Skip to content

Commit 36908a9

Browse files
author
Guillaume Chau
committed
fix(ui): improve task logs performance
1 parent 5792ed8 commit 36908a9

File tree

1 file changed

+36
-4
lines changed
  • packages/@vue/cli-ui/src/graphql-api/connectors

1 file changed

+36
-4
lines changed

packages/@vue/cli-ui/src/graphql-api/connectors/tasks.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,23 +280,32 @@ async function run (id, context) {
280280

281281
task.child = child
282282

283-
child.stdout.on('data', buffer => {
283+
const outPipe = logPipe(queue => {
284284
addLog({
285285
taskId: task.id,
286286
type: 'stdout',
287-
text: buffer.toString()
287+
text: queue
288288
}, context)
289289
})
290+
child.stdout.on('data', buffer => {
291+
outPipe.add(buffer.toString())
292+
})
290293

291-
child.stderr.on('data', buffer => {
294+
const errPipe = logPipe(queue => {
292295
addLog({
293296
taskId: task.id,
294297
type: 'stderr',
295-
text: buffer.toString()
298+
text: queue
296299
}, context)
297300
})
301+
child.stderr.on('data', buffer => {
302+
errPipe.add(buffer.toString())
303+
})
298304

299305
const onExit = async (code, signal) => {
306+
outPipe.flush()
307+
errPipe.flush()
308+
300309
log('Task exit', command, args, 'code:', code, 'signal:', signal)
301310

302311
// Plugin API
@@ -419,6 +428,29 @@ function open (id, context) {
419428
return true
420429
}
421430

431+
function logPipe (action) {
432+
let queue = ''
433+
let size = 0
434+
let time = Date.now()
435+
436+
return {
437+
add: (string) => {
438+
queue += string
439+
size++
440+
441+
if (size === 20 || Date.now() > time + 100) {
442+
action(queue)
443+
queue = ''
444+
size = 0
445+
time = Date.now()
446+
}
447+
},
448+
flush: () => {
449+
if (size) action(queue)
450+
}
451+
}
452+
}
453+
422454
module.exports = {
423455
list,
424456
findOne,

0 commit comments

Comments
 (0)