mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-15 03:01:37 -05:00
Fixed failing members import with label associations
no issue - When processing entries with new labels in parallel Bookshelf relations is trying to create them which caused unique key constraints to fail. To avoid the failure, all labels should be pre-created before proceeding with creating members
This commit is contained in:
parent
71e16bc6d2
commit
ef6586bfdc
1 changed files with 19 additions and 0 deletions
|
@ -126,6 +126,20 @@ const findOrCreateLabels = async (labels, options) => {
|
|||
}));
|
||||
};
|
||||
|
||||
const getUniqueMemberLabels = (members) => {
|
||||
const allLabels = [];
|
||||
|
||||
members.forEach((member) => {
|
||||
const labels = (member.labels && member.labels.split(',')) || [];
|
||||
|
||||
if (labels.length) {
|
||||
allLabels.push(...labels);
|
||||
}
|
||||
});
|
||||
|
||||
return _.uniq(allLabels);
|
||||
};
|
||||
|
||||
const members = {
|
||||
docName: 'members',
|
||||
|
||||
|
@ -438,6 +452,11 @@ const members = {
|
|||
importSetLabels.push(importLabel);
|
||||
}
|
||||
|
||||
// NOTE: member-specific labels have to be pre-created as they cause conflicts when processed
|
||||
// in parallel
|
||||
const memberLabels = serializeMemberLabels(getUniqueMemberLabels(frame.data.members));
|
||||
await findOrCreateLabels(memberLabels, frame.options);
|
||||
|
||||
return Promise.resolve().then(() => {
|
||||
const sanitized = sanitizeInput(frame.data.members);
|
||||
duplicateStripeCustomerIdCount = frame.data.members.length - sanitized.length;
|
||||
|
|
Loading…
Add table
Reference in a new issue