From 5c4369206a755138c9ab2b91a1e768c1d2f42877 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 24 Jul 2021 12:04:48 +0200 Subject: [PATCH] optimized content hash computation using raw queries --- src/services/content_hash.js | 6 +++--- src/services/sql.js | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/services/content_hash.js b/src/services/content_hash.js index 2fbbc18c6..51310ab18 100644 --- a/src/services/content_hash.js +++ b/src/services/content_hash.js @@ -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]; diff --git a/src/services/sql.js b/src/services/sql.js index 26f5d1f81..ff7f1ec36 100644 --- a/src/services/sql.js +++ b/src/services/sql.js @@ -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,