From 65c9f80e2c55b92e1534342f21f47f7e8fb46d83 Mon Sep 17 00:00:00 2001 From: williamlardier Date: Tue, 3 Oct 2023 09:02:47 +0200 Subject: [PATCH] wip --- .../metadata/mongoclient/MongoClientInterface.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/storage/metadata/mongoclient/MongoClientInterface.js b/lib/storage/metadata/mongoclient/MongoClientInterface.js index 403f708ed..c7031baf7 100644 --- a/lib/storage/metadata/mongoclient/MongoClientInterface.js +++ b/lib/storage/metadata/mongoclient/MongoClientInterface.js @@ -1045,19 +1045,20 @@ class MongoClientInterface { * gets object metadata for a list of objects * @param {String} bucketName bucket name * @param {Array} objects array of objects + * @param {Number} maxKeys max number of keys to return * @param {Object} log logger * @param {Function} callback callback * @return {undefined} */ - getObjects(bucketName, objects, log, callback) { + getObjects(bucketName, objects, maxKeys = 1000, log, callback) { const c = this.getCollection(bucketName); let vFormat = null; if (!Array.isArray(objects)) { return callback(errors.InternalError.customizeDescription('objects must be an array')); } - // We do not accept more than 1000 keys in a single request - if (objects.length > 1000) { - return callback(errors.InternalError.customizeDescription('cannot get more than 1000 objects')); + // We do not accept more than maxKeys keys in a single request + if (objects.length > maxKeys) { + return callback(errors.InternalError.customizeDescription(`cannot get more than ${maxKeys} objects`)); } // Function to process each document const processDoc = (doc, objName, params, key, cb) => { @@ -1103,7 +1104,7 @@ class MongoClientInterface { { 'value.deleted': { $exists: false } }, { 'value.deleted': { $eq: false } }, ], - }).toArray().then(docs => { + }).batchSize(maxKeys).toArray().then(docs => { // Create a Map to quickly find docs by their keys const docByKey = new Map(docs.map(doc => [doc._id, doc])); // Process each document using associated context (objName, params)