mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 21:40:39 +03:00
Moved batching logic inside the members importer module
no issue - This way importer is more self contained and controller logic doesn't have to know about batch sizes and other unecessary variables
This commit is contained in:
parent
c434666ba2
commit
78b4dff656
@ -596,18 +596,13 @@ module.exports = {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
const CHUNK_SIZE = 100;
|
return doImport({
|
||||||
const memberBatches = _.chunk(sanitized, CHUNK_SIZE);
|
members: sanitized,
|
||||||
|
allLabelModels,
|
||||||
return Promise.map(memberBatches, async (membersBatch) => {
|
importSetLabels,
|
||||||
return doImport({
|
imported,
|
||||||
membersBatch,
|
invalid,
|
||||||
allLabelModels,
|
createdBy
|
||||||
importSetLabels,
|
|
||||||
imported,
|
|
||||||
invalid,
|
|
||||||
createdBy
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// NOTE: grouping by context because messages can contain unique data like "customer_id"
|
// NOTE: grouping by context because messages can contain unique data like "customer_id"
|
||||||
|
@ -124,11 +124,19 @@ const doImport = async ({membersBatch: members, allLabelModels, importSetLabels,
|
|||||||
try {
|
try {
|
||||||
// TODO: below inserts most likely need to be wrapped into transaction
|
// TODO: below inserts most likely need to be wrapped into transaction
|
||||||
// to avoid creating orphaned member_labels connections
|
// to avoid creating orphaned member_labels connections
|
||||||
await db.knex('members')
|
const CHUNK_SIZE = 5000;
|
||||||
.insert(mappedMemberBatchData);
|
const chunkedMembers = _.chunk(mappedMemberBatchData, CHUNK_SIZE);
|
||||||
|
for (const data of chunkedMembers) {
|
||||||
|
await db.knex('members')
|
||||||
|
.insert(data);
|
||||||
|
}
|
||||||
|
|
||||||
await db.knex('members_labels')
|
const chunkedLebelAssociations = _.chunk(mappedMembersLabelsBatchAssociations, CHUNK_SIZE);
|
||||||
.insert(mappedMembersLabelsBatchAssociations);
|
|
||||||
|
for (const data of chunkedLebelAssociations) {
|
||||||
|
await db.knex('members_labels')
|
||||||
|
.insert(data);
|
||||||
|
}
|
||||||
|
|
||||||
imported.count += mappedMemberBatchData.length;
|
imported.count += mappedMemberBatchData.length;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user