mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
optimized content hash computation using raw queries
This commit is contained in:
parent
507a0e2e1d
commit
5c4369206a
@ -27,7 +27,7 @@ function getSectorHashes(tableName, primaryKeyName, whereBranch) {
|
|||||||
function getEntityHashes() {
|
function getEntityHashes() {
|
||||||
const startTime = new Date();
|
const startTime = new Date();
|
||||||
|
|
||||||
const hashRows = sql.getRows(`
|
const hashRows = sql.getRawRows(`
|
||||||
SELECT entityName,
|
SELECT entityName,
|
||||||
entityId,
|
entityId,
|
||||||
hash
|
hash
|
||||||
@ -37,11 +37,11 @@ function getEntityHashes() {
|
|||||||
|
|
||||||
// sorting is faster in memory
|
// sorting is faster in memory
|
||||||
// sorting by entityId is enough, hashes will be segmented by entityName later on anyway
|
// 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 = {};
|
const hashMap = {};
|
||||||
|
|
||||||
for (const {entityName, entityId, hash} of hashRows) {
|
for (const [entityName, entityId, hash] of hashRows) {
|
||||||
const entityHashMap = hashMap[entityName] = hashMap[entityName] || {};
|
const entityHashMap = hashMap[entityName] = hashMap[entityName] || {};
|
||||||
|
|
||||||
const sector = entityId[0];
|
const sector = entityId[0];
|
||||||
|
@ -134,6 +134,10 @@ function getRows(query, params = []) {
|
|||||||
return wrap(query, s => s.all(params));
|
return wrap(query, s => s.all(params));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRawRows(query, params = []) {
|
||||||
|
return wrap(query, s => s.raw().all(params));
|
||||||
|
}
|
||||||
|
|
||||||
function iterateRows(query, params = []) {
|
function iterateRows(query, params = []) {
|
||||||
return stmt(query).iterate(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
|
* @return {object[]} - array of all rows, each row is a map of column name to column value
|
||||||
*/
|
*/
|
||||||
getRows,
|
getRows,
|
||||||
|
getRawRows,
|
||||||
iterateRows,
|
iterateRows,
|
||||||
getManyRows,
|
getManyRows,
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user