-
Notifications
You must be signed in to change notification settings - Fork 60
Fix caching #82
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
Fix caching #82
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,13 +3,15 @@ | |
| var fs = require('fs'); | ||
|
|
||
| function objectValues(obj) { | ||
| if (typeof obj !== 'object') { | ||
| return []; | ||
| var values = []; | ||
| if (typeof obj === 'object') { | ||
| for (var key in obj) { | ||
| if (obj.hasOwnProperty(key)) { | ||
| values.push(obj[key]); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return Object.keys(obj).map(function (key) { | ||
| return obj[key]; | ||
| }); | ||
| return values | ||
| } | ||
|
|
||
| module.exports = DynamicCache; | ||
|
|
@@ -35,15 +37,31 @@ DynamicCache.prototype.update = function (cb) { | |
| this._queue = []; | ||
| } | ||
| }.bind(this); | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The bug in this is actually just that it double counts things, leading to circular structures creating an infinite loop.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that was definitely one problem. |
||
| var getDeps = function (filename) { | ||
| if (this._files[filename]) { | ||
| return [[filename]].concat(this._files[filename].map(getDeps)).reduce(function (a, b) { | ||
| return a.concat(b); | ||
| }); | ||
| } else { | ||
| return [filename]; | ||
| var dependencies = this._files[filename]; | ||
| var dependenciesSet = {}; | ||
|
|
||
| dependenciesSet[filename] = true; | ||
|
|
||
| var getSubDeps = function(deps){ | ||
| deps.forEach(function (dep, index) { | ||
| if (!dependenciesSet[dep]) { | ||
| dependenciesSet[dep] = true; | ||
| var subDeps = this._files[deps[index]]; | ||
| if (subDeps){ | ||
| getSubDeps(subDeps); | ||
| } | ||
| } | ||
| }, this); | ||
| }.bind(this) | ||
|
|
||
| if (dependencies) { | ||
| getSubDeps(dependencies); | ||
| } | ||
| return Object.keys(dependenciesSet); | ||
| }.bind(this); | ||
|
|
||
| files.forEach(function (filename) { | ||
| fs.stat(filename, function (err, stats) { | ||
| if (err || stats.mtime.getTime() !== this._time[filename]) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change? Your code is functionally identical to the shorter, simpler code that was there before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The performance was pretty bad so I tried to improve it. But you're right this probably doesn't change much.