optimized content hash computation using raw queries

This commit is contained in:
zadam 2021-07-24 12:04:48 +02:00
parent 507a0e2e1d
commit 5c4369206a
2 changed files with 8 additions and 3 deletions

View File

@ -27,7 +27,7 @@ function getSectorHashes(tableName, primaryKeyName, whereBranch) {
function getEntityHashes() {
const startTime = new Date();
const hashRows = sql.getRows(`
const hashRows = sql.getRawRows(`
SELECT entityName,
entityId,
hash
@ -37,11 +37,11 @@ function getEntityHashes() {
// sorting is faster in memory
// sorting by entityId is enough, hashes will be segmented by entityName later on anyway
hashRows.sort((a, b) => a.entityId < b.entityId ? -1 : 1);
hashRows.sort((a, b) => a[0] < b[0] ? -1 : 1);
const hashMap = {};
for (const {entityName, entityId, hash} of hashRows) {
for (const [entityName, entityId, hash] of hashRows) {
const entityHashMap = hashMap[entityName] = hashMap[entityName] || {};
const sector = entityId[0];

View File

@ -134,6 +134,10 @@ function getRows(query, params = []) {
return wrap(query, s => s.all(params));
}
function getRawRows(query, params = []) {
return wrap(query, s => s.raw().all(params));
}
function iterateRows(query, params = []) {
return stmt(query).iterate(params);
}
@ -314,6 +318,7 @@ module.exports = {
* @return {object[]} - array of all rows, each row is a map of column name to column value
*/
getRows,
getRawRows,
iterateRows,
getManyRows,