From b7f035b78e8efb9cbbf7bda8a4e47a96182ccc63 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Wed, 8 Feb 2023 15:10:17 +0500 Subject: [PATCH] core: simplify total notes counting in notebooks --- packages/core/models/notebook.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/core/models/notebook.js b/packages/core/models/notebook.js index 3f94e4a98..7244e6765 100644 --- a/packages/core/models/notebook.js +++ b/packages/core/models/notebook.js @@ -22,7 +22,7 @@ import Topics from "../collections/topics"; export default class Notebook { /** * - * @param {Object} notebook + * @param {any} notebook * @param {import ('../api').default} db */ constructor(notebook, db) { @@ -31,9 +31,11 @@ export default class Notebook { } get totalNotes() { - return this._notebook.topics.reduce((sum, topic) => { - return sum + this._db.notes.topicReferences.count(topic.id); - }, 0); + let count = 0; + for (const topic of this._notebook.topics) { + count += this._db.notes.topicReferences.count(topic.id); + } + return count; } get title() {