From b9c7b87fd9e4d2f01b3f7df1ca67d09c5597b9db Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Sun, 11 Mar 2018 22:52:01 -0400 Subject: [PATCH] Allow the minimum Elasticearch query size to be set per endpoint Reverse queries don't need as much deduping, for example --- middleware/sizeCalculator.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/middleware/sizeCalculator.js b/middleware/sizeCalculator.js index f8c6936c..9b577916 100644 --- a/middleware/sizeCalculator.js +++ b/middleware/sizeCalculator.js @@ -9,6 +9,10 @@ var MIN_QUERY_SIZE = 20; * incorporating padding for dedupe process */ function setup(min_size) { + if (min_size === undefined) { + min_size = MIN_QUERY_SIZE; + } + return function setQuerySize(req, res, next) { if (_.isUndefined(req.clean) || _.isUndefined(req.clean.size)) { return next(); @@ -25,8 +29,8 @@ function setup(min_size) { * @param {number} cleanSize * @returns {number} */ -function calculateSize(cleanSize) { - return Math.max(MIN_QUERY_SIZE, cleanSize * SIZE_PADDING); +function calculateSize(cleanSize, min_size) { + return Math.max(min_size, cleanSize * SIZE_PADDING); } module.exports = setup;