Skip to content

Commit 8e7d825

Browse files
committed
Migrate revisions in chunks ♻️
1 parent fdbd439 commit 8e7d825

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

server/script/migrateAssetsLocation.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const toPairs = require('lodash/toPairs');
2525

2626
const regex = /repository\/assets\/(.*)/;
2727
const REVISION_TYPES = ['REPOSITORY', 'ACTIVITY', 'CONTENT_ELEMENT'];
28+
const CHUNK_SIZE = 2000;
2829
const schemasIds = SCHEMAS.map(it => it.id);
2930

3031
const mapEntityToAction = {
@@ -117,12 +118,24 @@ async function migrateRepositoryContentElements(repositoryId, transaction) {
117118
}
118119

119120
async 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

Comments
 (0)