abmp-npm 1.1.81 → 1.1.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
const { bulkSaveMembers, getMemberBySlug } = require('../members-data-methods');
|
|
2
2
|
|
|
3
3
|
const { generateUpdatedMemberData } = require('./process-member-methods');
|
|
4
|
-
const {
|
|
4
|
+
const {
|
|
5
|
+
changeWixMembersEmails,
|
|
6
|
+
extractUrlCounter,
|
|
7
|
+
incrementUrlCounter,
|
|
8
|
+
extractBaseUrl,
|
|
9
|
+
} = require('./utils');
|
|
5
10
|
|
|
6
11
|
/**
|
|
7
12
|
* Ensures unique URLs within a batch of members by deduplicating URLs
|
|
@@ -23,7 +28,8 @@ async function ensureUniqueUrlsInBatch(memberDataList) {
|
|
|
23
28
|
return;
|
|
24
29
|
}
|
|
25
30
|
|
|
26
|
-
|
|
31
|
+
// Extract the base URL (without any counter) for grouping
|
|
32
|
+
const baseUrl = extractBaseUrl(member.url);
|
|
27
33
|
if (!urlGroups.has(baseUrl)) {
|
|
28
34
|
urlGroups.set(baseUrl, []);
|
|
29
35
|
}
|
|
@@ -53,10 +59,10 @@ async function ensureUniqueUrlsInBatch(memberDataList) {
|
|
|
53
59
|
continue;
|
|
54
60
|
}
|
|
55
61
|
|
|
56
|
-
// Sort members to ensure consistent ordering
|
|
62
|
+
// Sort members to ensure consistent ordering
|
|
57
63
|
members.sort((a, b) => {
|
|
58
|
-
if (a.
|
|
59
|
-
return String(a.
|
|
64
|
+
if (a.url && b.url) {
|
|
65
|
+
return String(a.url).localeCompare(String(b.url));
|
|
60
66
|
}
|
|
61
67
|
return 0;
|
|
62
68
|
});
|
|
@@ -102,7 +108,9 @@ async function ensureUniqueUrlsInBatch(memberDataList) {
|
|
|
102
108
|
});
|
|
103
109
|
|
|
104
110
|
console.log(
|
|
105
|
-
`Deduplicated ${
|
|
111
|
+
`Deduplicated ${
|
|
112
|
+
members.length
|
|
113
|
+
} members with base URL "${baseUrl}" (DB max: ${dbMaxCounter}, batch max: ${batchMaxCounter}, start: ${startIndex}): ${members
|
|
106
114
|
.map(m => m.url)
|
|
107
115
|
.join(', ')}`
|
|
108
116
|
);
|
|
@@ -144,10 +152,6 @@ const bulkProcessAndSaveMemberData = async ({
|
|
|
144
152
|
const validMemberData = processedMemberDataList.filter(
|
|
145
153
|
data => data !== null && data !== undefined
|
|
146
154
|
);
|
|
147
|
-
|
|
148
|
-
// Ensure unique URLs within the batch to prevent duplicates (also checks DB for cross-page conflicts)
|
|
149
|
-
await ensureUniqueUrlsInBatch(validMemberData);
|
|
150
|
-
|
|
151
155
|
if (validMemberData.length === 0) {
|
|
152
156
|
return {
|
|
153
157
|
totalProcessed: memberDataList.length,
|
|
@@ -156,9 +160,14 @@ const bulkProcessAndSaveMemberData = async ({
|
|
|
156
160
|
processingTime: Date.now() - startTime,
|
|
157
161
|
};
|
|
158
162
|
}
|
|
163
|
+
const newMembers = validMemberData.filter(data => data.isNewToDb);
|
|
164
|
+
const existingMembers = validMemberData.filter(data => !data.isNewToDb);
|
|
165
|
+
// Ensure unique URLs within the batch to prevent duplicates (also checks DB for cross-page conflicts)
|
|
166
|
+
const uniqueUrlsNewToDBMembersList = await ensureUniqueUrlsInBatch(newMembers);
|
|
167
|
+
const uniqueUrlsMembersData = [...uniqueUrlsNewToDBMembersList, ...existingMembers];
|
|
159
168
|
const toChangeWixMembersEmails = [];
|
|
160
|
-
const toSaveMembersData =
|
|
161
|
-
const { isLoginEmailChanged, ...restMemberData } = member;
|
|
169
|
+
const toSaveMembersData = uniqueUrlsMembersData.map(member => {
|
|
170
|
+
const { isLoginEmailChanged, isNewToDb: _isNewToDb, ...restMemberData } = member;
|
|
162
171
|
if (member.contactId && isLoginEmailChanged) {
|
|
163
172
|
toChangeWixMembersEmails.push(member);
|
|
164
173
|
}
|
|
@@ -22,6 +22,18 @@ const extractUrlCounter = url => {
|
|
|
22
22
|
return isNumeric ? parseInt(lastSegment, 10) : -1;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
+
const extractBaseUrl = url => {
|
|
26
|
+
if (!url) return url;
|
|
27
|
+
const urlParts = url.split('-');
|
|
28
|
+
const lastSegment = urlParts[urlParts.length - 1];
|
|
29
|
+
const isNumeric = /^\d+$/.test(lastSegment);
|
|
30
|
+
if (isNumeric && urlParts.length > 1) {
|
|
31
|
+
// Remove the numeric counter to get the base URL
|
|
32
|
+
return urlParts.slice(0, -1).join('-');
|
|
33
|
+
}
|
|
34
|
+
// No counter found, return the URL as-is
|
|
35
|
+
return url;
|
|
36
|
+
};
|
|
25
37
|
const incrementUrlCounter = (existingUrl, baseUrl) => {
|
|
26
38
|
if (existingUrl && existingUrl === baseUrl) {
|
|
27
39
|
console.log(
|
|
@@ -95,4 +107,5 @@ module.exports = {
|
|
|
95
107
|
createFullName,
|
|
96
108
|
extractUrlCounter,
|
|
97
109
|
incrementUrlCounter,
|
|
110
|
+
extractBaseUrl,
|
|
98
111
|
};
|