Last active
February 22, 2017 18:50
-
-
Save gmaclennan/112c6786511c63c406f2eb64d4157b9d to your computer and use it in GitHub Desktop.
osm-p2p-db deletion batch ops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
index ec505de..ff29709 100644 | |
--- a/index.js | |
+++ b/index.js | |
@@ -191,25 +191,13 @@ DB.prototype.del = function (key, opts, cb) { | |
// OsmVersion, Opts -> [OsmBatchOp] | |
DB.prototype._getDocumentDeletionBatchOps = function (key, opts, cb) { | |
var self = this | |
- self.kv.get(key, function (err, docs) { | |
+ self.kv.get(key, {fields: true}, function (err, docs) { | |
if (err) return cb(err) | |
- docs = mapObj(docs, function (version, value) { | |
- if (value.deleted) { | |
- return { | |
- id: key, | |
- version: version, | |
- deleted: true | |
- } | |
- } else { | |
- return value.value | |
- } | |
- }) | |
- | |
- var fields = {} | |
+ var fields = {v: opts.value || {}} | |
var links = opts.keys || Object.keys(docs) | |
links.forEach(function (ln) { | |
- var v = docs[ln] || {} | |
+ var v = docs[ln].v || {} | |
if (v.lat !== undefined && v.lon !== undefined) { | |
if (!fields.points) fields.points = [] | |
fields.points.push({ lat: v.lat, lon: v.lon }) | |
@@ -218,6 +206,10 @@ DB.prototype._getDocumentDeletionBatchOps = function (key, opts, cb) { | |
if (!fields.refs) fields.refs = [] | |
fields.refs.push.apply(fields.refs, v.refs) | |
} | |
+ if (fields.v.type && v.type !== fields.v.type) { | |
+ return cb(new Error('type mismatch')) // improve error desc. | |
+ } | |
+ fields.v.type = v.type | |
}) | |
cb(null, [ { type: 'del', key: key, links: links, fields: fields } ]) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment