[Pkg-javascript-commits] [node-leveldown] 130/492: remove useBatch option on writeStream
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:13:52 UTC 2014
This is an automated email from the git hooks/post-receive script.
andrewrk-guest pushed a commit to annotated tag rocksdb-0.10.1
in repository node-leveldown.
commit b11fc4b0e4db2649973d1113e22a54ea76fd4435
Author: Rod Vagg <rod at vagg.org>
Date: Thu Dec 20 10:44:50 2012 +1100
remove useBatch option on writeStream
---
README.md | 4 ----
lib/write-stream.js | 17 +++++------------
test/write-stream-test.js | 2 ++
3 files changed, 7 insertions(+), 16 deletions(-)
diff --git a/README.md b/README.md
index 05fd784..600b459 100644
--- a/README.md
+++ b/README.md
@@ -321,10 +321,6 @@ db.writeStream()
The standard `write()`, `end()`, `destroy()` and `destroySoon()` methods are implemented on the WriteStream. `'drain'`, `'error'`, `'close'` and `'pipe'` events are emitted.
-Additionally, you can supply an options object as the first parameter to `writeStream()` with the following option:
-
-* `'useBatch'` *(boolean, default: `true`)*: if set to `false`, your *WriteStream* will avoid the use of `batch()` and use `put()` to write all data to the database. Since `batch()` is much quicker than multiple `put()` operations, you are advised to leave this as `true` unless you have a good reason to change it.
-
#### Pipes and Node Stream compatibility
A ReadStream can be piped directly to a WriteStream, allowing for easy copying of an entire database. A simple `copy()` operation is included in LevelUP that performs exactly this on two open databases:
diff --git a/lib/write-stream.js b/lib/write-stream.js
index 7ab9f17..31869d2 100644
--- a/lib/write-stream.js
+++ b/lib/write-stream.js
@@ -2,7 +2,6 @@
var Stream = require('stream').Stream
, concatStream = require('concat-stream')
- , async = require('async')
, extend = require('./util').extend
@@ -89,7 +88,7 @@ WriteStream.prototype = {
}
this._process()
}.bind(this)
- , buffer
+ , buffer, entry
if (this._status != 'ready' && this.writable) {
if (this._buffer.length && this._status != 'closed')
@@ -101,16 +100,10 @@ WriteStream.prototype = {
this._status = 'writing'
buffer = this._buffer
this._buffer = []
- if ((this._options.useBatch != null && !this._options.useBatch) || this._buffer.length == 1) {
- async.forEach(
- buffer
- , function (entry, cb) {
- if (entry.key === undefined || entry.value === undefined)
- return cb()
- this._db.put(entry.key, entry.value, cb)
- }.bind(this)
- , cb
- )
+ if (this._buffer.length == 1) {
+ entry = this._buffer.pop()
+ if (entry.key !== undefined && entry.value !== undefined)
+ this._db.put(entry.key, entry.value, cb)
} else {
this._db.batch(buffer.map(function (d) {
return { type: 'put', key: d.key, value: d.value }
diff --git a/test/write-stream-test.js b/test/write-stream-test.js
index 1e36232..bc854c6 100644
--- a/test/write-stream-test.js
+++ b/test/write-stream-test.js
@@ -86,6 +86,7 @@ buster.testCase('WriteStream', {
}.bind(this))
}
+ /*
// exactly the same as previous but should avoid batch() writes
, 'test WriteStream with async writes and useBatch=false': function (done) {
this.openTestDatabase(function (db) {
@@ -120,6 +121,7 @@ buster.testCase('WriteStream', {
)
}.bind(this))
}
+ */
// at the moment, destroySoon() is basically just end()
, 'test destroySoon()': function (done) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-leveldown.git
More information about the Pkg-javascript-commits
mailing list