@@ -5,6 +5,7 @@ import Dataset from "../../models/dataset"
55import Permission from "../../models/permission"
66import Comment from "../../models/comment"
77import Deletion from "../../models/deletion"
8+ import { queueIndexDataset } from "../../queues/producer-methods"
89import * as Sentry from "@sentry/node"
910
1011/**
@@ -20,6 +21,7 @@ import * as Sentry from "@sentry/node"
2021export async function userMigration ( orcid : string , userId : string ) {
2122 const session = await mongoose . startSession ( )
2223 try {
24+ const updateDatasets : Record < string , boolean > = { }
2325 await session . withTransaction ( async ( ) => {
2426 try {
2527 // Load both original records
@@ -55,6 +57,7 @@ export async function userMigration(orcid: string, userId: string) {
5557 // Record this dataset uploader as migrated
5658 migration . datasets . push ( dataset . id )
5759 await dataset . save ( { session } )
60+ updateDatasets [ dataset . id ] = true
5861 }
5962
6063 // Migrate dataset permissions
@@ -70,6 +73,7 @@ export async function userMigration(orcid: string, userId: string) {
7073 // Record this permission as migrated
7174 migration . permissions . push ( permission . toObject ( ) )
7275 await permission . save ( { session } )
76+ updateDatasets [ permission . datasetId ] = true
7377 }
7478
7579 // Migrate dataset deletions
@@ -110,6 +114,10 @@ export async function userMigration(orcid: string, userId: string) {
110114 // Save success
111115 migration . success = true
112116 await migration . save ( { session } )
117+ // Request reindexing
118+ for ( const updateDataset of Object . keys ( updateDatasets ) ) {
119+ queueIndexDataset ( updateDataset )
120+ }
113121 } catch ( err ) {
114122 Sentry . captureException ( err )
115123 throw err
0 commit comments