abmp-npm 1.1.136 → 1.1.138
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.
|
@@ -16,7 +16,8 @@ async function ensureUniqueUrlsInBatch(memberDataList) {
|
|
|
16
16
|
return memberDataList;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
// Group members by their normalized base URL
|
|
19
|
+
// Group members by their normalized base URL (case-insensitive to avoid
|
|
20
|
+
// "John-12" and "john-12" being treated as different when slugs are matched case-insensitively)
|
|
20
21
|
const urlGroups = new Map();
|
|
21
22
|
|
|
22
23
|
memberDataList.forEach(member => {
|
|
@@ -24,16 +25,16 @@ async function ensureUniqueUrlsInBatch(memberDataList) {
|
|
|
24
25
|
return;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
// Extract the base URL (without any counter) for grouping
|
|
28
28
|
const baseUrl = extractBaseUrl(member.url);
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const groupKey = baseUrl.toLowerCase();
|
|
30
|
+
if (!urlGroups.has(groupKey)) {
|
|
31
|
+
urlGroups.set(groupKey, { members: [], baseUrl });
|
|
31
32
|
}
|
|
32
|
-
urlGroups.get(
|
|
33
|
+
urlGroups.get(groupKey).members.push(member);
|
|
33
34
|
});
|
|
34
35
|
|
|
35
36
|
// For each group, check database and assign unique URLs sequentially
|
|
36
|
-
for (const [
|
|
37
|
+
for (const [, { members, baseUrl }] of urlGroups.entries()) {
|
|
37
38
|
if (members.length <= 1) {
|
|
38
39
|
// Single member - still check DB to ensure it doesn't conflict with other pages
|
|
39
40
|
const member = members[0];
|
|
@@ -75,8 +76,7 @@ async function ensureUniqueUrlsInBatch(memberDataList) {
|
|
|
75
76
|
// Find the highest existing counter among all members in this batch group
|
|
76
77
|
let batchMaxCounter = -1;
|
|
77
78
|
members.forEach(member => {
|
|
78
|
-
const
|
|
79
|
-
const urlCounter = extractUrlCounter(originalUrl);
|
|
79
|
+
const urlCounter = extractUrlCounter(member.url);
|
|
80
80
|
if (urlCounter > batchMaxCounter) {
|
|
81
81
|
batchMaxCounter = urlCounter;
|
|
82
82
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { COLLECTIONS } = require('../public/consts');
|
|
2
2
|
|
|
3
3
|
const { ensureUniqueUrlsInBatch } = require('./daily-pull/bulk-process-methods');
|
|
4
|
+
const { ensureUniqueUrl } = require('./daily-pull/process-member-methods');
|
|
4
5
|
const { wixData } = require('./elevated-modules');
|
|
5
6
|
const { bulkSaveMembers } = require('./members-data-methods');
|
|
6
7
|
const { queryAllItems } = require('./utils');
|
|
@@ -27,4 +28,31 @@ async function copyContactIdToWixMemberId() {
|
|
|
27
28
|
return await bulkSaveMembers(updatedMembers, COLLECTIONS.MEMBERS_DATA);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
async function createMissingUrls() {
|
|
32
|
+
const query = wixData.query(COLLECTIONS.MEMBERS_DATA).isEmpty('url');
|
|
33
|
+
const members = await queryAllItems(query);
|
|
34
|
+
console.log(
|
|
35
|
+
'membersWithoutUrls info',
|
|
36
|
+
JSON.stringify({
|
|
37
|
+
count: members.length,
|
|
38
|
+
membersIds: members.map(m => m.memberId),
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const membersWithGeneratedUrlsPromises = members.map(async member => ({
|
|
43
|
+
...member,
|
|
44
|
+
url: await ensureUniqueUrl({
|
|
45
|
+
url: member.url,
|
|
46
|
+
memberId: member.memberId,
|
|
47
|
+
fullName: member.fullName,
|
|
48
|
+
}),
|
|
49
|
+
}));
|
|
50
|
+
const membersWithGeneratedUrls = await Promise.all(membersWithGeneratedUrlsPromises);
|
|
51
|
+
//recheck urls in same batch to avoid duplicates
|
|
52
|
+
const uniqueUrlsUpdatedMembers = await ensureUniqueUrlsInBatch(membersWithGeneratedUrls);
|
|
53
|
+
const urls = uniqueUrlsUpdatedMembers.map(m => m.url).filter(Boolean);
|
|
54
|
+
console.log('unique urls', [...new Set(urls)]);
|
|
55
|
+
return await bulkSaveMembers(uniqueUrlsUpdatedMembers, COLLECTIONS.MEMBERS_DATA);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = { deduplicateURls, copyContactIdToWixMemberId, createMissingUrls };
|