From 620e896a892682985dfeee63c6481330b4b9fca6 Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 2 Oct 2020 21:53:25 +0200 Subject: [PATCH] faster content hash computation via in memory sorting --- src/services/content_hash.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/services/content_hash.js b/src/services/content_hash.js index 6946cc33b..47ae6e535 100644 --- a/src/services/content_hash.js +++ b/src/services/content_hash.js @@ -12,9 +12,11 @@ const RecentNote = require('../entities/recent_note'); const Option = require('../entities/option'); function getSectorHashes(tableName, primaryKeyName, whereBranch) { - const hashes = sql.getRows(`SELECT ${primaryKeyName} AS id, hash FROM ${tableName} ` - + (whereBranch ? `WHERE ${whereBranch} ` : '') - + ` ORDER BY ${primaryKeyName}`); + const hashes = sql.getRows(`SELECT ${primaryKeyName} AS id, hash FROM ${tableName}` + + (whereBranch ? ` WHERE ${whereBranch} ` : '')); + + // sorting is faster in memory + hashes.sort((a, b) => a.id < b.id ? -1 : 1); const map = {};