From 4b80bab88ef15fc68c93585a21bd04c2b6c46177 Mon Sep 17 00:00:00 2001 From: scienceasdf Date: Sat, 30 Jan 2021 03:16:33 +0800 Subject: [PATCH] fix: rebuilding tree error when the page number is large enough in sqlite (#2830) When the total page number is large enough (usually about 80+), sqlite will throw error: "Too many variables". This commit reduces the chunk size for sqlite configuration. --- server/jobs/rebuild-tree.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/jobs/rebuild-tree.js b/server/jobs/rebuild-tree.js index 270586f1..a91e7e40 100644 --- a/server/jobs/rebuild-tree.js +++ b/server/jobs/rebuild-tree.js @@ -57,8 +57,14 @@ module.exports = async (pageId) => { await WIKI.models.knex.table('pageTree').truncate() if (tree.length > 0) { // -> Save in chunks, because of per query max parameters (35k Postgres, 2k MSSQL, 1k for SQLite) - for (const chunk of _.chunk(tree, 100)) { - await WIKI.models.knex.table('pageTree').insert(chunk) + if ((WIKI.config.db.type !== 'sqlite')) + for (const chunk of _.chunk(tree, 100)) { + await WIKI.models.knex.table('pageTree').insert(chunk) + } + } else { + for (const chunk of _.chunk(tree, 60)) { + await WIKI.models.knex.table('pageTree').insert(chunk) + } } }