From a257831c6ca50dda95bbe6b33984129cb1943361 Mon Sep 17 00:00:00 2001 From: alancnet Date: Thu, 19 Dec 2019 13:48:05 -0800 Subject: [PATCH] fix: rebuild-tree exceeds mssql parameter limit (#1328) * fix: rebuild-tree exceeds mssql's parameter limit * docs: details per query max parameters limits Co-authored-by: Nicolas Giard --- server/jobs/rebuild-tree.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/jobs/rebuild-tree.js b/server/jobs/rebuild-tree.js index 81e7ecf4..bf82417a 100644 --- a/server/jobs/rebuild-tree.js +++ b/server/jobs/rebuild-tree.js @@ -53,7 +53,10 @@ module.exports = async (pageId) => { await WIKI.models.knex.table('pageTree').truncate() if (tree.length > 0) { - await WIKI.models.knex.table('pageTree').insert(tree) + // -> 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) + } } await WIKI.models.knex.destroy()