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); callback(err);
return; return;
} }
var metadata = {}; var metadata = rows.reduce(function(metadata, row){
rows.forEach(function(row) {
var table = row.base_table; var table = row.base_table;
var schema = row._cdb_schema_name; var schema = row._cdb_schema_name;
var table_metadata = metadata[table]; var table_metadata = metadata[table];
if ( !table_metadata ) { if ( !table_metadata ) {
table_metadata = metadata[table] = {}; table_metadata = metadata[table] = {};
} }
table_metadata[row.z] = { table: row.overview_table }; table_metadata[row.z] = { table: row.overview_table };
table_metadata.schema = schema; table_metadata.schema = schema;
}); return metadata;
}, {});
return callback(null, metadata); return callback(null, metadata);
}); });
}; };