diff --git a/binding.cc b/binding.cc index e223061d..2250a11c 100644 --- a/binding.cc +++ b/binding.cc @@ -1589,9 +1589,10 @@ struct BatchWorker final : public PriorityWorker { Database* database, napi_value callback, leveldb::WriteBatch* batch, - bool sync) + bool sync, + bool hasData) : PriorityWorker(env, database, callback, "leveldown.batch.do"), - batch_(batch) { + batch_(batch), hasData_(hasData) { options_.sync = sync; } @@ -1600,11 +1601,14 @@ struct BatchWorker final : public PriorityWorker { } void DoExecute () override { - SetStatus(database_->WriteBatch(options_, batch_)); + if (hasData_) { + SetStatus(database_->WriteBatch(options_, batch_)); + } } leveldb::WriteOptions options_; leveldb::WriteBatch* batch_; + bool hasData_; }; /** @@ -1655,15 +1659,8 @@ NAPI_METHOD(batch_do) { } } - if (hasData) { - BatchWorker* worker = new BatchWorker(env, database, callback, batch, sync); - worker->Queue(); - } else { - delete batch; - napi_value argv; - napi_get_null(env, &argv); - CallFunction(env, callback, 1, &argv); - } + BatchWorker* worker = new BatchWorker(env, database, callback, batch, sync, hasData); + worker->Queue(); NAPI_RETURN_UNDEFINED(); } @@ -1789,7 +1786,9 @@ struct BatchWriteWorker final : public PriorityWorker { ~BatchWriteWorker () {} void DoExecute () override { - SetStatus(batch_->Write(sync_)); + if (batch_->hasData_) { + SetStatus(batch_->Write(sync_)); + } } Batch* batch_; diff --git a/package.json b/package.json index 87e888cf..b0e9e2a6 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "prebuild-android-arm64": "IMAGE=android-arm64 ./scripts/cross-compile" }, "dependencies": { - "abstract-leveldown": "~6.0.0", + "abstract-leveldown": "~6.0.3", "fast-future": "~1.0.2", "napi-macros": "~1.8.1", "node-gyp-build": "~3.8.0"