Refactor: use reduce for collecting overviews metadata

This commit is contained in:
Javier Goizueta 2016-04-20 17:24:16 +02:00
parent 57cba3d511
commit ecbae52abe

View File

@ -31,18 +31,17 @@ OverviewsMetadataApi.prototype.getOverviewsMetadata = function (username, sql, c
callback(err);
return;
}
var metadata = {};
rows.forEach(function(row) {
var metadata = rows.reduce(function(metadata, row){
var table = row.base_table;
var schema = row._cdb_schema_name;
var table_metadata = metadata[table];
if ( !table_metadata ) {
table_metadata = metadata[table] = {};
table_metadata = metadata[table] = {};
}
table_metadata[row.z] = { table: row.overview_table };
table_metadata.schema = schema;
});
return metadata;
}, {});
return callback(null, metadata);
});
};