Просмотр исходного кода

Merge branch 'master' into feat/opentelemetry

Yuki Takei 1 год назад
Родитель
Сommit
f0029906ac
3 измененных файлов с 85 добавлено и 32 удалено
  1. 24 1
      CHANGELOG.md
  2. 1 4
      apps/app/src/pages/share/[[...path]].page.tsx
  3. 60 27
      bin/data-migrations/src/index.js

+ 24 - 1
CHANGELOG.md

@@ -1,9 +1,32 @@
 # Changelog
 
-## [Unreleased](https://github.com/weseek/growi/compare/v7.1.8...HEAD)
+## [Unreleased](https://github.com/weseek/growi/compare/v7.1.9...HEAD)
 
 *Please do not manually update this file. We've automated the process.*
 
+## [v7.1.9](https://github.com/weseek/growi/compare/v7.1.8...v7.1.9) - 2025-02-03
+
+### 💎 Features
+
+* feat: Add error handling for data migration (#9582) @miya
+
+### 🚀 Improvement
+
+* imprv: Data migration script performance (#9599) @miya
+* imprv: Initialization for Passport strategies (#9353) @yuki-takei
+* imprv: Make data migration type safe (#9590) @miya
+* imprv: Printing styles (#9576) @yuki-takei
+
+### 🐛 Bug Fixes
+
+* fix: Serializing page data for share link (#9602) @yuki-takei
+
+### 🧰 Maintenance
+
+* ci(deps-dev): bump vite from 5.4.6 to 5.4.12 (#9574) @dependabot
+* ci(deps): bump mongoose from 6.13.0 to 6.13.6 (#9570) @dependabot
+* ci(deps): bump katex from 0.16.11 to 0.16.21 (#9564) @dependabot
+
 ## [v7.1.8](https://github.com/weseek/growi/compare/v7.1.7...v7.1.8) - 2025-01-21
 
 ### 🐛 Bug Fixes

+ 1 - 4
apps/app/src/pages/share/[[...path]].page.tsx

@@ -63,10 +63,7 @@ superjson.registerCustom<IShareLinkRelatedPage, string>(
   {
     isApplicable: (v): v is IShareLinkRelatedPage => {
       return v != null
-        && v.toObject != null
-        && v.lastUpdateUser != null
-        && v.creator != null
-        && v.revision != null;
+        && v.toObject != null;
     },
     serialize: (v) => { return superjson.stringify(v.toObject()) },
     deserialize: (v) => { return superjson.parse(v) },

+ 60 - 27
bin/data-migrations/src/index.js

@@ -25,48 +25,81 @@ if (migrationModules.length === 0) {
 
 /** @type {ReplaceLatestRevisions} */
 function replaceLatestRevisions(body, migrationModules) {
-  var replacedBody = body;
-  migrationModules.forEach((migrationModule) => {
-    replacedBody = migrationModule(replacedBody);
-  });
-  return replacedBody;
+  return migrationModules.reduce((replacedBody, module) => module(replacedBody), body);
 }
 
-/** @type {Operations} */
-var operations = [];
-pagesCollection.find({}).forEach((/** @type {any} */ doc) => {
-  if (doc.revision) {
-    try {
-      var revision = revisionsCollection.findOne({ _id: doc.revision });
+var pipeline = [
+  // Join pages with revisions
+  {
+    $lookup: {
+      from: 'revisions',
+      localField: 'revision',
+      foreignField: '_id',
+      as: 'revisionDoc',
+    },
+  },
+  // Unwind the revision array
+  {
+    $unwind: '$revisionDoc',
+  },
+  // Project only needed fields
+  {
+    $project: {
+      _id: '$revisionDoc._id',
+      body: '$revisionDoc.body',
+    },
+  },
+];
 
-      if (revision == null || revision.body == null) {
-        return;
-      }
 
-      var replacedBody = replaceLatestRevisions(revision.body, [...migrationModules]);
-      var operation = {
+try {
+  /** @type {Operations} */
+  var operations = [];
+  var processedCount = 0;
+
+  var cursor = pagesCollection.aggregate(pipeline, {
+    allowDiskUse: true,
+    cursor: { batchSize },
+  });
+
+  while (cursor.hasNext()) {
+    var doc = cursor.next();
+
+    if (doc == null || doc.body == null) {
+      continue;
+    }
+
+    try {
+      var replacedBody = replaceLatestRevisions(doc.body, [...migrationModules]);
+
+      operations.push({
         updateOne: {
-          filter: { _id: revision._id },
+          filter: { _id: doc._id },
           update: {
             $set: { body: replacedBody },
           },
         },
-      };
-      operations.push(operation);
+      });
+
+      processedCount++;
 
-      // bulkWrite per 100 revisions
-      if (operations.length > (batchSize - 1)) {
+      if (operations.length >= batchSize || !cursor.hasNext()) {
         revisionsCollection.bulkWrite(operations);
-        // sleep time can be set from env var
-        sleep(batchSizeInterval);
+        if (batchSizeInterval > 0) {
+          sleep(batchSizeInterval);
+        }
+
         operations = [];
       }
     }
     catch (err) {
-      print(`Error in updating revision ${doc.revision}: ${err}`);
+      print(`Error processing document ${doc?._id}: ${err}`);
     }
   }
-});
-revisionsCollection.bulkWrite(operations);
 
-print('migration complete!');
+  print('Migration complete!');
+}
+catch (err) {
+  print(`Fatal error during migration: ${err}`);
+  throw err;
+}