@@ -25,6 +25,7 @@ const toPairs = require('lodash/toPairs');
2525
2626const regex = / r e p o s i t o r y \/ a s s e t s \/ ( .* ) / ;
2727const REVISION_TYPES = [ 'REPOSITORY' , 'ACTIVITY' , 'CONTENT_ELEMENT' ] ;
28+ const CHUNK_SIZE = 2000 ;
2829const schemasIds = SCHEMAS . map ( it => it . id ) ;
2930
3031const mapEntityToAction = {
@@ -117,12 +118,24 @@ async function migrateRepositoryContentElements(repositoryId, transaction) {
117118}
118119
119120async function migrateRepositoryRevisions ( repositoryId , transaction ) {
120- const revisions = await Revision . findAll ( {
121- where : {
122- repositoryId,
123- entity : { [ Op . in ] : REVISION_TYPES }
124- } ,
121+ const options = {
122+ where : { repositoryId, entity : { [ Op . in ] : REVISION_TYPES } } ,
125123 transaction
124+ } ;
125+ const count = await Revision . count ( options ) ;
126+ const pages = Math . ceil ( count / CHUNK_SIZE ) ;
127+ return Promise . each (
128+ Array . from ( { length : pages } , ( _ , i ) => i + 1 ) ,
129+ page => migrateRevisionsChunk ( { page, options, transaction } )
130+ ) ;
131+ }
132+
133+ async function migrateRevisionsChunk ( { page, options, transaction } ) {
134+ const offset = ( page - 1 ) * CHUNK_SIZE ;
135+ const revisions = await Revision . findAll ( {
136+ ...options ,
137+ offset,
138+ limit : CHUNK_SIZE
126139 } ) ;
127140 return Promise . each ( revisions , async it => {
128141 const payload = await migrateRevision ( it ) ;
0 commit comments