Skip to content

Instantly share code, notes, and snippets.

@gmaclennan
Last active February 22, 2017 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmaclennan/112c6786511c63c406f2eb64d4157b9d to your computer and use it in GitHub Desktop.
Save gmaclennan/112c6786511c63c406f2eb64d4157b9d to your computer and use it in GitHub Desktop.
osm-p2p-db deletion batch ops
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