Skip to content

Build your personal knowledge base with Trilium Notes

optimized content hash computation using raw queries

zadam5c4369206a75
diff --git a/src/services/content_hash.js b/src/services/content_hash.js
index 2fbbc18c6b..51310ab182 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 26f5d1f81d..ff7f1ec360 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,