Răsfoiți Sursa

Merge pull request #1876 from overleaf/spd-cleanup-stubs-no-user

Handle user stubs with no user in cleanup script

GitOrigin-RevId: 810134f0876bc595f2d749921929b52dae4e7958
Simon Detheridge 7 ani în urmă
părinte
comite
4b0a445337
1 a modificat fișierele cu 16 adăugiri și 0 ștergeri
  1. 16 0
      services/web/scripts/cleanup_dangling_user_stubs.js

+ 16 - 0
services/web/scripts/cleanup_dangling_user_stubs.js

@@ -48,6 +48,14 @@ db.userstubs.aggregate(
       Number(argv.limit || '10'),
       Number(argv.limit || '10'),
       (stub, callback) => {
       (stub, callback) => {
         if (commit) {
         if (commit) {
+          if (stub.users.length === 0) {
+            console.log('Deleting stub without users:', stub._id)
+            return db.userstubs.remove({ _id: stub._id }, callback)
+          }
+          if (stub.users.length > 1) {
+            console.log('Found stub with multiple users:', stub)
+            return callback()
+          }
           console.log(
           console.log(
             'Processing stub',
             'Processing stub',
             stub._id,
             stub._id,
@@ -61,6 +69,14 @@ db.userstubs.aggregate(
             callback
             callback
           )
           )
         } else {
         } else {
+          if (stub.users.length === 0) {
+            console.log('Would delete stub without users:', stub._id)
+            return callback()
+          }
+          if (stub.users.length > 1) {
+            console.log('Found stub with multiple users:', stub)
+            return callback()
+          }
           console.log(
           console.log(
             'Would call UserMapper._updateUserStubReferences with:',
             'Would call UserMapper._updateUserStubReferences with:',
             stub.overleaf,
             stub.overleaf,