使用 CouchDB,我在尝试计算一组自动化测试结果的“最后一次通过”和“最后一次失败”时间时,性能非常差。
我有一个约 5000 条记录的数据库:
{
"completionTime": "2013-06-06T17:28:09.384Z",
"environment": "ENV1",
"passed": true,
"duration": 59142,
"summary": "",
"origin": {
"rowId": "1",
"worksheet": "Sheet1",
"workbook": "book.xlsm"
}
}
我有一个用地图定义的视图:
function(run) {
if (run.environment && run.origin && run.origin.rowId && run.origin.worksheet && run.origin.workbook && run.completionTime) {
var key = [run.environment, run.origin.rowId, run.origin.worksheet, run.origin.workbook]
var completionTime = Date.parse(run.completionTime)
if (run.passed)
emit(key, [completionTime, null] );
else
emit(key, [null, completionTime] );
}
}
并减少:
function (key, values, rereduce) {
var latestPass = null;
var latestFail = null;
for (var i = 0; i < values.length; i++) {
latestPass = Math.max(values[i][0], latestPass);
latestFail = Math.max(values[i][1], latestFail);
}
return [latestPass, latestFail];
}
当查询这个视图的所有结果(大约 750 个)时,它需要 10-50 秒,这比我预期的要慢得多。
我在做一些明显错误的事情吗?