@@ -18,72 +18,59 @@ export async function fixActivityRelationsMemberId(
1818 args : IFixActivityRelationsMemberIdArgs ,
1919) : Promise < void > {
2020 const BATCH_SIZE = args . batchSize ?? 500
21- const BUFFER_TARGET = args . bufferTargetSize ?? 50
2221
23- // Always use all platforms every run
2422 const platforms = Object . values ( PlatformType )
2523 let currentPlatformIndex = args . currentPlatformIndex ?? 0
2624
27- const recordsBuffer = [ ]
28-
29- while ( recordsBuffer . length < BUFFER_TARGET && currentPlatformIndex < platforms . length ) {
30- const platform = platforms [ currentPlatformIndex ]
31-
32- if ( args . testRun ) {
33- console . log ( 'Current platform:' , platform )
34- }
35-
36- const records = await findMembersWithWrongActivityRelations ( platform , BATCH_SIZE )
37-
38- if ( records . length === 0 ) {
39- console . log ( `Platform ${ platform } returned 0 results. Skipping.` )
40- currentPlatformIndex ++ // Move to next platform
41- continue
42- }
43-
44- // Fill buffer from this platform
45- const slotsLeft = BUFFER_TARGET - recordsBuffer . length
46- recordsBuffer . push ( ...records . slice ( 0 , slotsLeft ) )
47- }
48-
49- // No more platforms and empty buffer → stop workflow
50- if ( recordsBuffer . length === 0 ) {
51- console . log ( 'No more activity relations to fix!' )
25+ if ( currentPlatformIndex >= platforms . length ) {
26+ console . log ( 'All platforms exhausted. Workflow complete!' )
5227 return
5328 }
5429
55- // Process the batch (even if < BUFFER_TARGET)
56- await Promise . all (
57- recordsBuffer . map ( async ( record ) => {
58- const correctMemberId = await findMemberIdByUsernameAndPlatform (
59- record . username ,
60- record . platform ,
61- )
62-
63- if ( args . testRun ) {
64- console . log ( 'Moving activity relations!' , {
65- fromId : record . memberId ,
66- toId : correctMemberId ,
67- username : record . username ,
68- platform : record . platform ,
69- } )
70- }
71-
72- await moveActivityRelations (
73- record . memberId ,
74- correctMemberId ,
75- record . username ,
76- record . platform ,
77- )
78- } ) ,
79- )
30+ const platform = platforms [ currentPlatformIndex ]
31+
32+ if ( args . testRun ) console . log ( 'Processing platform:' , platform )
33+
34+ // Take a batch from current platform
35+ const records = await findMembersWithWrongActivityRelations ( platform , BATCH_SIZE )
36+
37+ if ( records . length === 0 ) {
38+ console . log ( `Platform ${ platform } has no more records. Moving to next platform.` )
39+ currentPlatformIndex ++
40+ } else {
41+ // Process the batch immediately
42+ await Promise . all (
43+ records . map ( async ( record ) => {
44+ const correctMemberId = await findMemberIdByUsernameAndPlatform (
45+ record . username ,
46+ record . platform ,
47+ )
48+
49+ if ( args . testRun ) {
50+ console . log ( 'Moving activity relations!' , {
51+ fromId : record . memberId ,
52+ toId : correctMemberId ,
53+ username : record . username ,
54+ platform : record . platform ,
55+ } )
56+ }
57+
58+ await moveActivityRelations (
59+ record . memberId ,
60+ correctMemberId ,
61+ record . username ,
62+ record . platform ,
63+ )
64+ } ) ,
65+ )
66+ }
8067
8168 if ( args . testRun ) {
8269 console . log ( 'Test run completed - stopping after first batch!' )
8370 return
8471 }
8572
86- // Continue workflow at the next platform
73+ // Continue workflow for next batch (same platform or next platform)
8774 await continueAsNew < typeof fixActivityRelationsMemberId > ( {
8875 ...args ,
8976 currentPlatformIndex,
0 commit comments