Created
February 22, 2011 22:22
-
-
Save hoodoos/839553 to your computer and use it in GitHub Desktop.
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
riak.client.add([['clientinfo', key], ['clientzonesinfo', key]]) | |
.map(function(v, keydata, args){ | |
if(v.values){ | |
var result = {} | |
if(v.bucket == args.clientBucket){ | |
var keysToGet = []; | |
result.clientInfo = Riak.mapValuesJson(v)[0]; | |
result.clientInfo.gds.forEach(function(gds){ | |
keysToGet.push([args.bspBucket, gds.bsp, result]); | |
keysToGet.push([args.bspCardExc, gds.bsp, result]); | |
}); | |
return keysToGet; | |
} | |
else{ | |
result[v.bucket] = Riak.mapValuesJson(v)[0]; | |
return [['','',result]]; | |
} | |
} | |
else{ | |
return []; | |
} | |
}, args) | |
.map(function(v, keydata, args){ | |
if(v.values){ | |
var result = keydata; | |
if(v.bucket == args.bspBucket){ | |
var bspInfo = Riak.mapValuesJson(v)[0]; | |
if(result.bspInfos == undefined){ | |
result.bspInfos = {}; | |
} | |
result.bspInfos[bspInfo.country] = bspInfo; | |
return [[args.pgBucket, bspInfo.pg, result]]; | |
} | |
else if(v.bucket == args.bspCardExc){ | |
var bspCardExc = Riak.mapValuesJson(v)[0]; | |
if(result.bspExc == undefined){ | |
result.bspExc = {}; | |
} | |
result.bspExc[bspCardExc.country] = bspCardExc; | |
return [['','',result]]; | |
} | |
} | |
else{ | |
return []; | |
} | |
}, args) | |
.map(function(v, keydata, args){ | |
if(v.values){ | |
var result = keydata; | |
if(v.bucket == args.pgBucket){ | |
var pg = Riak.mapValuesJson(v)[0]; | |
if(result.pg == undefined){ | |
result.pg = {} | |
} | |
result.pg[pg.tag] = pg; | |
return [result]; | |
} | |
else{ | |
return [result]; | |
} | |
} | |
else{ | |
return []; | |
} | |
}, args) | |
.reduce(function(v, args){ | |
var r = {} | |
function process(obj){ | |
for(var key in obj){ | |
if(key != 'not_found'){ | |
r[key] = obj[key]; | |
} | |
else{ | |
process(obj[key].keydata); | |
} | |
} | |
} | |
v.forEach(function(vv){ | |
process(vv); | |
}); | |
return [r]; | |
}) | |
.run(function(err, result){ | |
callback(undefined, result); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment