Permalink
Browse files

Bit more sync

  • Loading branch information...
1 parent 4fb2400 commit cea681c40365588ca1d8b106664da5628b88a72d @temas temas committed Mar 19, 2013
Showing with 34 additions and 33 deletions.
  1. +34 −33 lib/ijod.js
View
@@ -406,6 +406,7 @@ IJOD.prototype.commitAddTransaction = function(timings, cbDone) {
if (!this.transactionItems || this.transactionItems.length === 0) {
return cbDone();
}
+ var startTime = Date.now();
//console.log("Committing %d items", this.transactionItems.length);
var totalSize = this.transactionItems.reduce(function(prev, cur, idx, arr) {
return prev + arr[idx].length;
@@ -414,41 +415,41 @@ IJOD.prototype.commitAddTransaction = function(timings, cbDone) {
var writeBuffer = new Buffer(totalSize);
var idx = 0;
var self = this;
- lutil.forEachSeries(self.transactionItems, function(item, cb) {
+ self.transactionItems.forEach(function(item) {
item.copy(writeBuffer, idx);
idx += item.length;
- cb();
- }, function(err) {
- var startTime = Date.now();
- backend.put(self.path, writeBuffer, function (err) {
- timings["commit-backend"] = Date.now() - startTime;
- writeBuffer = null;
- if (!err) {
- logger.debug("Saving %d entries to ijod", self.transactionQueries.length);
- // compose everything together, gnarly dude
- var allSql = "";
- var allBinds = [];
- var id;
- self.transactionQueries.forEach(function(query){
- id = query.id; // just need one of them since all in the same base
- allSql += query.sql + '; ';
- allBinds = allBinds.concat(query.binds);
- });
- dbMod(id, allSql, allBinds, function(err){
- timings["commit-db"] = Date.now() - startTime;
- if(err) logger.warn("err bulk writing",err);
- instruments.timing({
- "ijod.save_time": (Date.now() - startTime)
- }).send();
- instruments.increment("ijod.puts").send();
- self.transactionItems = null;
- cbDone();
- });
- } else {
- instruments.increment("ijod.put_errors").send();
- self.abortAddTransaction(cbDone);
- }
- });
+ });
+ timings["commit-prep"] = Date.now() - startTime;
+ startTime = Date.now();
+ backend.put(self.path, writeBuffer, function (err) {
+ timings["commit-backend"] = Date.now() - startTime;
+ startTime = Date.now();
+ writeBuffer = null;
+ if (!err) {
+ logger.debug("Saving %d entries to ijod", self.transactionQueries.length);
+ // compose everything together, gnarly dude
+ var allSql = "";
+ var allBinds = [];
+ var id;
+ self.transactionQueries.forEach(function(query){
+ id = query.id; // just need one of them since all in the same base
+ allSql += query.sql + '; ';
+ allBinds = allBinds.concat(query.binds);
+ });
+ dbMod(id, allSql, allBinds, function(err){
+ timings["commit-db"] = Date.now() - startTime;
+ if(err) logger.warn("err bulk writing",err);
+ instruments.timing({
+ "ijod.save_time": (Date.now() - startTime)
+ }).send();
+ instruments.increment("ijod.puts").send();
+ self.transactionItems = null;
+ cbDone();
+ });
+ } else {
+ instruments.increment("ijod.put_errors").send();
+ self.abortAddTransaction(cbDone);
+ }
});
};

0 comments on commit cea681c

Please sign in to comment.