Skip to content

Instantly share code, notes, and snippets.

@lxbarth
Created February 7, 2011 15:48
Show Gist options
  • Save lxbarth/814565 to your computer and use it in GitHub Desktop.
Save lxbarth/814565 to your computer and use it in GitHub Desktop.
diff --git a/data/data.js b/data/data.js
index ebe5f19..beacbfe 100644
--- a/data/data.js
+++ b/data/data.js
@@ -407,26 +407,32 @@ Dataset.prototype.validate = function(dataVersion, schemaVersion, cb) {
var start = new Date().getTime();
var totalcount = 0;
var errorcount = 0;
- for (row in result) {
- totalcount += 1;
- var data = result[row].doc;
- var report = env.validate(data, schema);
- if (report.errors.length) {
- errorcount += 1;
- report.errors.forEach(function(err) {
- validation.errors.push('Error: ' + [report.instance.resolveURI(err.uri), err.message].join(' : '));
- });
- }
+ var keys = Object.keys(result);
+ var key = null;
+ var data = {};
+ if (key = keys.shift()) {
+ process.nextTick(function() {
+ data = result[key].doc;
+ var report = env.validate(data, schema);
+ if (report.errors.length) {
+ errorcount += 1;
+ report.errors.forEach(function(err) {
+ validation.errors.push('Error: ' + [report.instance.resolveURI(err.uri), err.message].join(' : '));
+ });
+ }
+ });
+ }
+ else {
+ validation.totalcount = totalcount;
+ validation.errorcount = errorcount;
+ var end = new Date().getTime();
+ validation.ran = start;
+ validation.runtime = (end - start) / 1000;
+ var combo = dataVersion + '+' + schemaVersion;
+ that.setValidationResults(combo, {});
+ that.save();
+ cb(validation);
}
- validation.totalcount = totalcount;
- validation.errorcount = errorcount;
- var end = new Date().getTime();
- validation.ran = start;
- validation.runtime = (end - start) / 1000;
- var combo = dataVersion + '+' + schemaVersion;
- that.setValidationResults(combo, {});
- that.save();
- cb(validation);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment