Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Significantly improved addFile/changeFile/removeFile performance. #3726

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 5 additions & 8 deletions lib/file-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class FileList {
return lastCompletedRefresh
}

// TODO - Change this so that it's not a getter. Getters shouldn't do lots of processing!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: TODO: instead of TODO - :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi - I really don't want to spend the 15 minutes on context switching to remove a '-'. Can this be accepted as is (assuming no other issues)?

get files () {
const served = []
const included = {}
Expand Down Expand Up @@ -172,18 +173,18 @@ class FileList {
const excluded = this._findExcluded(path)
if (excluded) {
log.debug(`Add file "${path}" ignored. Excluded by "${excluded}".`)
return this.files
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devoto13
I think not returning the file list is a breaking change. Should we not hold on to this change for release v7+ (#3503)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jginsburgn Yes, I think it should be better to land it in a major release.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

}

const pattern = this._findIncluded(path)
if (!pattern) {
log.debug(`Add file "${path}" ignored. Does not match any pattern.`)
return this.files
return
}

if (this._exists(path)) {
log.debug(`Add file "${path}" ignored. Already in the list.`)
return this.files
return
}

const file = new File(path)
Expand All @@ -195,7 +196,6 @@ class FileList {

log.info(`Added file "${path}".`)
this._emitModified()
return this.files
}

async changeFile (path, force) {
Expand All @@ -204,7 +204,7 @@ class FileList {

if (!file) {
log.debug(`Changed file "${path}" ignored. Does not match any file in the list.`)
return this.files
return
}

const [stat] = await Promise.all([statAsync(path), this._refreshing])
Expand All @@ -214,7 +214,6 @@ class FileList {
log.info(`Changed file "${path}".`)
this._emitModified(force)
}
return this.files
}

async removeFile (path) {
Expand All @@ -224,12 +223,10 @@ class FileList {
if (file) {
helper.arrayRemove(this._getFilesByPattern(pattern.pattern), file)
log.info(`Removed file "${path}".`)

this._emitModified()
} else {
log.debug(`Removed file "${path}" ignored. Does not match any file in the list.`)
}
return this.files
}
}

Expand Down
28 changes: 14 additions & 14 deletions test/unit/file-list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,32 +464,32 @@ describe('FileList', () => {

it('does not add excluded files', () => {
return list.refresh().then((before) => {
return list.addFile('/secret/hello.txt').then((files) => {
expect(files.served).to.be.eql(before.served)
return list.addFile('/secret/hello.txt').then(() => {
expect(list.files.served).to.be.eql(before.served)
})
})
})

it('does not add already existing files', () => {
return list.refresh().then((before) => {
return list.addFile('/some/a.js').then((files) => {
expect(files.served).to.be.eql(before.served)
return list.addFile('/some/a.js').then(() => {
expect(list.files.served).to.be.eql(before.served)
})
})
})

it('does not add unmatching files', () => {
return list.refresh().then((before) => {
return list.addFile('/some/a.ex').then((files) => {
expect(files.served).to.be.eql(before.served)
return list.addFile('/some/a.ex').then(() => {
expect(list.files.served).to.be.eql(before.served)
})
})
})

it('adds the file to the correct bucket', () => {
return list.refresh().then((before) => {
return list.addFile('/some/d.js').then((files) => {
expect(pathsFrom(files.served)).to.contain('/some/d.js')
return list.addFile('/some/d.js').then(() => {
expect(pathsFrom(list.files.served)).to.contain('/some/d.js')
const bucket = list.buckets.get('/some/*.js')
expect(pathsFrom(bucket)).to.contain('/some/d.js')
})
Expand Down Expand Up @@ -531,8 +531,8 @@ describe('FileList', () => {
list = new List(patterns('/a.*'), [], emitter, preprocess)

return list.refresh().then(() => {
return list.addFile('/a.js').then((files) => {
expect(findFile('/a.js', files.served).mtime).to.eql(new Date('2012-01-01'))
return list.addFile('/a.js').then(() => {
expect(findFile('/a.js', list.files.served).mtime).to.eql(new Date('2012-01-01'))
})
})
})
Expand Down Expand Up @@ -597,10 +597,10 @@ describe('FileList', () => {
mockFs._touchFile('/some/b.js', '3020-01-01')
modified.resetHistory()

return list.changeFile('/some/b.js').then((files) => {
return list.changeFile('/some/b.js').then(() => {
clock.tick(101)
expect(modified).to.have.been.calledOnce
expect(findFile('/some/b.js', files.served).mtime).to.be.eql(new Date('3020-01-01'))
expect(findFile('/some/b.js', list.files.served).mtime).to.be.eql(new Date('3020-01-01'))
})
})
})
Expand Down Expand Up @@ -719,8 +719,8 @@ describe('FileList', () => {
return list.refresh().then((files) => {
modified.resetHistory()
return list.removeFile('/some/a.js')
}).then((files) => {
expect(pathsFrom(files.served)).to.be.eql([
}).then(() => {
expect(pathsFrom(list.files.served)).to.be.eql([
'/some/b.js',
'/a.txt'
])
Expand Down