map-reduce
Advanced tools
Comparing version 1.0.1 to 1.0.2
50
index.js
@@ -41,3 +41,2 @@ | ||
//OH NO, THIS STILL DOESN'T SUPPORT DELETES PROPERLY. | ||
db.hooks.pre(function (batch) { | ||
@@ -49,3 +48,3 @@ var l = batch.length | ||
var name = view.name | ||
if(view.start <= key && key <= view.end && batch[i].type === 'put') | ||
if(view.start <= key && key <= view.end /*&& batch[i].type === 'put'*/) | ||
batch.push(db.queue('map:'+name, key, false)) | ||
@@ -92,3 +91,2 @@ }) | ||
var values = [] | ||
key.push(true) | ||
@@ -102,3 +100,2 @@ | ||
//save the collection | ||
//get the parent group | ||
@@ -114,4 +111,2 @@ var _key = key.slice(); _key.pop() | ||
if(_key.length) { | ||
//if(key[0] <= 0) return | ||
//queue the parent group to be reduced. | ||
@@ -121,13 +116,4 @@ _key.pop() | ||
} | ||
/*** | ||
encountered a problem with doing hooks this way, | ||
if I turn a batch into a put, then db won't emit the post event, | ||
and there will be no post hook. | ||
***/ | ||
if(batch.length > 1) | ||
db.batch(batch, cb) | ||
else | ||
db.put(batch[0].key, batch[0].value, cb) | ||
db.batch(batch, cb) | ||
}) | ||
@@ -140,4 +126,4 @@ } | ||
var keys = [], sync = true, self = this | ||
db.get(bucket('map', data.key), function (err, oldKeys) { | ||
var mapOldKeys = bucket('map', data.key) | ||
db.get(mapOldKeys, function (err, oldKeys) { | ||
oldKeys = oldKeys ? JSON.parse(oldKeys) : [] | ||
@@ -148,7 +134,8 @@ var maps = [] | ||
if(!~keys.indexOf(key)) { | ||
keys.push(key) | ||
var _key = bucket([key, data.key]) | ||
keys.push([key, data.key]) | ||
maps.push({ | ||
type: 'put', | ||
//also, queue the next reduce. | ||
key: bucket([key, data.key]), | ||
key: _key, | ||
value: value | ||
@@ -163,11 +150,24 @@ }) | ||
emit.emit = emit | ||
view.map.call(emit, data.key, data.value, emit) | ||
//don't do a map if this was a delete. | ||
if('undefined' !== typeof data.value) | ||
view.map.call(emit, data.key, data.value, emit) | ||
//setting this will make emit throw if it is called again later. | ||
sync = false | ||
oldKeys.forEach(function (_key) { | ||
if(!~keys.indexOf(_key)) | ||
map.unshift({type: 'del', key: _key}) | ||
oldKeys.forEach(function (kAry) { | ||
maps.unshift({type: 'del', key: bucket(kAry)}) | ||
kAry = kAry.slice(); kAry.pop() | ||
maps.push( | ||
db.queue('reduce:'+name, JSON.stringify(kAry), false) | ||
) | ||
}) | ||
//save the maps. | ||
maps.push({ | ||
type: keys.length ? 'put' : 'del', | ||
key: mapOldKeys, | ||
value: keys.length ? JSON.stringify(keys) : null | ||
}) | ||
db.batch(maps, cb) | ||
@@ -174,0 +174,0 @@ }) |
{ | ||
"name": "map-reduce", | ||
"description": "map-reduce on leveldb", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"homepage": "https://github.com/dominictarr/map-reduce", | ||
@@ -13,4 +13,4 @@ "repository": { | ||
"range-bucket": "~0.0.2", | ||
"level-hooks": "~1.1.0", | ||
"level-queue": "~0.0.3", | ||
"level-hooks": "~1.1.1", | ||
"level-queue": "~0.0.4", | ||
"level-live-stream": "0.0.2" | ||
@@ -17,0 +17,0 @@ }, |
21265
16
449
Updatedlevel-hooks@~1.1.1
Updatedlevel-queue@~0.0.4