Przeglądaj źródła

fix: remove caching of collection names and retrieve them directly for validation

Shun Miyazawa 7 miesięcy temu
rodzic
commit
4d4fe5a4d8
1 zmienionych plików z 2 dodań i 13 usunięć
  1. 2 13
      apps/app/src/server/routes/apiv3/export.js

+ 2 - 13
apps/app/src/server/routes/apiv3/export.js

@@ -18,13 +18,6 @@ import { apiV3FormValidator } from '../../middlewares/apiv3-form-validator';
 const logger = loggerFactory('growi:routes:apiv3:export');
 const logger = loggerFactory('growi:routes:apiv3:export');
 const router = express.Router();
 const router = express.Router();
 
 
-
-/**
-   * @type {string[]}
-   * @description Cache of all collection names in the database
-   */
-let allCollectionNames = [];
-
 /**
 /**
  * @swagger
  * @swagger
  *
  *
@@ -163,13 +156,9 @@ module.exports = (crowi) => {
         .bail()
         .bail()
 
 
         .custom(async(value) => {
         .custom(async(value) => {
-          // Cache all collection names if not already cached
-          if (allCollectionNames.length === 0) {
-            const listCollectionsResult = await mongoose.connection.db.listCollections().toArray();
-            allCollectionNames = listCollectionsResult.map(collectionObj => collectionObj.name);
-          }
-
           // Check if all the collections in the request body exist in the database
           // Check if all the collections in the request body exist in the database
+          const listCollectionsResult = await mongoose.connection.db.listCollections().toArray();
+          const allCollectionNames = listCollectionsResult.map(collectionObj => collectionObj.name);
           if (!value.every(v => allCollectionNames.includes(v))) {
           if (!value.every(v => allCollectionNames.includes(v))) {
             throw new Error('Invalid collections');
             throw new Error('Invalid collections');
           }
           }