【发布时间】:2016-07-30 11:38:49
【问题描述】:
总的来说,我知道问题是什么,但我不知道如何解决它。
我有一个简单的地图功能:
function(doc) {
if(doc.Type === 'Mission'){
for(var i in doc.Sections){
emit(doc._id, {_id:doc.Sections[i].id});
}
}
}
根据 map-function 的结果,我使用 list-function 进行一些格式化:
function(head,req){
var result=[];
var row;
topo = require('lib/topojson');
while(row=getRow()){
if (row !== null) {
if(row.value._id){
row.doc.Geometry.properties.IDs.Section_ID = row.value._id;
}else{
row.doc.Geometry.properties.IDs.Section_ID = row.value;
}
geojson = {
type: "Feature",
geometry: row.doc.Geometry.geometry,
properties: row.doc.Geometry.properties
};
result.push(geojson);
}else{
send(JSON.stringify({
status_code: 404
}));
}
}
send(JSON.stringify(result));
}
与 map 函数匹配的文档越多,使用 list 函数进行处理所需的时间就越长。限制因素是 couchjs 视图服务器。首先必须对 map 函数的结果进行序列化,然后列表函数才能完成工作。
正如我所写,对于少量文档,处理时间并不显着,但随着文档数量的增加,列表函数进行处理的时间也会增加。
有人想改进我格式化结果的方式吗? 让客户做工作更好吗?
【问题讨论】:
标签: couchdb