sr-npm 1.7.1313 → 1.7.1314

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.
Files changed (2) hide show
  1. package/backend/data.js +134 -81
  2. package/package.json +1 -1
package/backend/data.js CHANGED
@@ -176,34 +176,34 @@ async function saveJobsDataToCMS() {
176
176
  return titleA.localeCompare(titleB, undefined, { sensitivity: 'base', numeric: true });
177
177
  });
178
178
 
179
- const chunkSize = 1000;
180
- let totalSaved = 0;
181
- const totalChunks = Math.ceil(jobsData.length / chunkSize);
179
+ // const chunkSize = 1000;
180
+ // let totalSaved = 0;
181
+ // const totalChunks = Math.ceil(jobsData.length / chunkSize);
182
182
 
183
- console.log(
184
- `Processing ${jobsData.length} jobs in ${totalChunks} chunks of max ${chunkSize} items each`
185
- );
186
- console.log("truncating jobs collection");
187
- await wixData.truncate(COLLECTIONS.JOBS);
188
- await chunkedBulkOperation({
189
- items: jobsData,
190
- chunkSize,
191
- processChunk: async (chunk, chunkNumber) => {
192
- console.log(`Saving chunk ${chunkNumber}/${totalChunks}: ${chunk.length} jobs`);
193
- try {
194
- const result = await wixData.bulkSave(COLLECTIONS.JOBS, chunk);
195
- const saved = result.inserted + result.updated || chunk.length;
196
- totalSaved += saved;
197
- console.log(
198
- `✓ Chunk ${chunkNumber} saved successfully. Inserted: ${result.inserted}, Updated: ${result.updated}`
199
- );
200
- } catch (error) {
201
- console.error(`✗ Error saving chunk ${chunkNumber}:`, error);
202
- throw error;
203
- }
204
- },
205
- });
206
- console.log(`✓ All chunks processed. Total jobs saved: ${totalSaved}/${jobsData.length}`);
183
+ // console.log(
184
+ // `Processing ${jobsData.length} jobs in ${totalChunks} chunks of max ${chunkSize} items each`
185
+ // );
186
+
187
+ // await chunkedBulkOperation({
188
+ // items: jobsData,
189
+ // chunkSize,
190
+ // processChunk: async (chunk, chunkNumber) => {
191
+ // console.log(`Saving chunk ${chunkNumber}/${totalChunks}: ${chunk.length} jobs`);
192
+ // try {
193
+ // const result = await wixData.bulkSave(COLLECTIONS.JOBS, chunk);
194
+ // const saved = result.inserted + result.updated || chunk.length;
195
+ // totalSaved += saved;
196
+ // console.log(
197
+ // `✓ Chunk ${chunkNumber} saved successfully. Inserted: ${result.inserted}, Updated: ${result.updated}`
198
+ // );
199
+ // } catch (error) {
200
+ // console.error(`✗ Error saving chunk ${chunkNumber}:`, error);
201
+ // throw error;
202
+ // }
203
+ // },
204
+ // });
205
+ // console.log(`✓ All chunks processed. Total jobs saved: ${totalSaved}/${jobsData.length}`);
206
+ return jobsData;
207
207
  }
208
208
 
209
209
  async function insertJobsReference(id, valueId) {
@@ -262,9 +262,9 @@ async function saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS() {
262
262
  console.log("inserted jobs references to custom values collection successfully");
263
263
  }
264
264
 
265
- let totalUpdated = 0;
266
- let totalFailed = 0;
267
- let totalProcessed = 0;
265
+ // let totalUpdated = 0;
266
+ // let totalFailed = 0;
267
+ // let totalProcessed = 0;
268
268
 
269
269
  console.log(
270
270
  `Total jobs in database without descriptions: ${jobsWithNoDescriptions?.items?.length}`
@@ -276,17 +276,12 @@ async function saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS() {
276
276
  }
277
277
 
278
278
 
279
- const API_CHUNK_SIZE = 80;
280
- const pageChunks = Math.ceil(jobsWithNoDescriptions.items.length / API_CHUNK_SIZE);
279
+ // const API_CHUNK_SIZE = 80;
280
+ //const pageChunks = Math.ceil(jobsWithNoDescriptions.items.length / API_CHUNK_SIZE);
281
281
  const richContentConverterToken = await getTokenFromCMS(TOKEN_NAME.RICH_CONTENT_CONVERTER_TOKEN);
282
- await chunkedBulkOperation({
283
- items: jobsWithNoDescriptions.items,
284
- chunkSize: API_CHUNK_SIZE,
285
- processChunk: async (chunk, chunkNumber) => {
286
- console.log(` Processing API chunk ${chunkNumber}/${pageChunks} (${chunk.length} jobs)`);
287
- const chunkPromises = chunk.map(async job => {
288
- try {
289
- const jobDetails = await fetchJobDescription(job._id);
282
+
283
+ jobsWithNoDescriptions=jobsWithNoDescriptions.map(async job => {
284
+ const jobDetails = await fetchJobDescription(job._id);
290
285
  const richContentDescription=await htmlRichContentConverter(jobDetails.jobAd.sections,richContentConverterToken);
291
286
  const jobLocation = fetchJobLocation(jobDetails);
292
287
  const {applyLink , referFriendLink} = fetchApplyAndReferFriendLink(jobDetails);
@@ -297,40 +292,62 @@ async function saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS() {
297
292
  applyLink: applyLink,
298
293
  referFriendLink: referFriendLink,
299
294
  };
300
- await wixData.update(COLLECTIONS.JOBS, updatedJob);
301
- return { success: true, jobId: job._id, title: job.title };
302
- } catch (error) {
303
- console.error(` ❌ Failed to update ${job.title} (${job._id}):`, error);
304
- return { success: false, jobId: job._id, title: job.title, error: error.message };
305
- }
306
- });
307
- const chunkResults = await Promise.all(chunkPromises);
308
- const chunkSuccesses = chunkResults.filter(r => r.success).length;
309
- const chunkFailures = chunkResults.filter(r => !r.success).length;
310
- totalUpdated += chunkSuccesses;
311
- totalFailed += chunkFailures;
312
- totalProcessed += chunk.length;
313
- console.log(
314
- ` API chunk ${chunkNumber} completed: ${chunkSuccesses} success, ${chunkFailures} failed`
315
- );
316
- },
317
- });
318
-
319
-
320
-
321
- console.log(`\n✅ Finished updating ALL job descriptions`);
322
- console.log(`📊 Final Results:`);
323
- console.log(` Total jobs processed: ${totalProcessed}`);
324
- console.log(` Total updated: ${totalUpdated}`);
325
- console.log(` Total failed: ${totalFailed}`);
326
-
327
- return {
328
- success: true,
329
- totalProcessed: totalProcessed,
330
- totalUpdated: totalUpdated,
331
- totalFailed: totalFailed,
332
- message: `Successfully updated ${totalUpdated} job descriptions out of ${totalProcessed} total jobs`,
333
- };
295
+ return updatedJob;
296
+ })
297
+ return {success: true, updatedJobs: jobsWithNoDescriptions};
298
+
299
+ // await chunkedBulkOperation({
300
+ // items: jobsWithNoDescriptions.items,
301
+ // chunkSize: API_CHUNK_SIZE,
302
+ // processChunk: async (chunk, chunkNumber) => {
303
+ // console.log(` Processing API chunk ${chunkNumber}/${pageChunks} (${chunk.length} jobs)`);
304
+ // const chunkPromises = chunk.map(async job => {
305
+ // try {
306
+ // const jobDetails = await fetchJobDescription(job._id);
307
+ // const richContentDescription=await htmlRichContentConverter(jobDetails.jobAd.sections,richContentConverterToken);
308
+ // const jobLocation = fetchJobLocation(jobDetails);
309
+ // const {applyLink , referFriendLink} = fetchApplyAndReferFriendLink(jobDetails);
310
+ // const updatedJob = {
311
+ // ...job,
312
+ // locationAddress: jobLocation,
313
+ // jobDescription: richContentDescription,
314
+ // applyLink: applyLink,
315
+ // referFriendLink: referFriendLink,
316
+ // };
317
+ // await wixData.update(COLLECTIONS.JOBS, updatedJob);
318
+ // return { success: true, jobId: job._id, title: job.title };
319
+ // } catch (error) {
320
+ // console.error(` Failed to update ${job.title} (${job._id}):`, error);
321
+ // return { success: false, jobId: job._id, title: job.title, error: error.message };
322
+ // }
323
+ // });
324
+ // const chunkResults = await Promise.all(chunkPromises);
325
+ // const chunkSuccesses = chunkResults.filter(r => r.success).length;
326
+ // const chunkFailures = chunkResults.filter(r => !r.success).length;
327
+ // totalUpdated += chunkSuccesses;
328
+ // totalFailed += chunkFailures;
329
+ // totalProcessed += chunk.length;
330
+ // console.log(
331
+ // ` API chunk ${chunkNumber} completed: ${chunkSuccesses} success, ${chunkFailures} failed`
332
+ // );
333
+ // },
334
+ // });
335
+
336
+
337
+
338
+ // console.log(`\n✅ Finished updating ALL job descriptions`);
339
+ // console.log(`📊 Final Results:`);
340
+ // console.log(` Total jobs processed: ${totalProcessed}`);
341
+ // console.log(` Total updated: ${totalUpdated}`);
342
+ // console.log(` Total failed: ${totalFailed}`);
343
+
344
+ // return {
345
+ // success: true,
346
+ // totalProcessed: totalProcessed,
347
+ // totalUpdated: totalUpdated,
348
+ // totalFailed: totalFailed,
349
+ // message: `Successfully updated ${totalUpdated} job descriptions out of ${totalProcessed} total jobs`,
350
+ // };
334
351
  } catch (error) {
335
352
  console.error('❌ Error in updateJobDescriptions:', error);
336
353
  throw error;
@@ -507,20 +524,56 @@ async function syncJobsFast() {
507
524
  try{
508
525
  console.log("Syncing jobs fast");
509
526
  await createCollections();
510
- await clearCollections();
527
+ // await clearCollections();
511
528
  await fillSecretManagerMirror();
512
529
 
513
- console.log("saving jobs data to CMS");
514
- await saveJobsDataToCMS();
515
- console.log("saved jobs data to CMS successfully");
530
+ console.log("saving jobs data to CMS");//change comment
531
+ const jobsData = await saveJobsDataToCMS(); //change name
532
+ console.log("jobsData inside syncJobsFast: ",jobsData);
533
+ console.log("saved jobs data to CMS successfully");//change comment
534
+
535
+ console.log("saving jobs descriptions and location apply url to CMS");//change comment
536
+ const status=await saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS();
537
+
538
+ console.log("status inside syncJobsFast: ",status);
539
+ if(status.success){
540
+ await clearCollections();
541
+ const updatedJobs=status.updatedJobs;
542
+ const chunkSize = 1000;
543
+ let totalSaved = 0;
544
+ const totalChunks = Math.ceil(updatedJobs.length / chunkSize);
545
+
546
+ console.log(
547
+ `Processing ${updatedJobs.length} jobs in ${totalChunks} chunks of max ${chunkSize} items each`
548
+ );
516
549
 
517
- console.log("saving jobs descriptions and location apply url to CMS");
518
- await saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS();
550
+ await chunkedBulkOperation({
551
+ items: updatedJobs,
552
+ chunkSize,
553
+ processChunk: async (chunk, chunkNumber) => {
554
+ console.log(`Saving chunk ${chunkNumber}/${totalChunks}: ${chunk.length} jobs`);
555
+ try {
556
+ const result = await wixData.bulkSave(COLLECTIONS.JOBS, chunk);
557
+ const saved = result.inserted + result.updated || chunk.length;
558
+ totalSaved += saved;
559
+ console.log(
560
+ `✓ Chunk ${chunkNumber} saved successfully. Inserted: ${result.inserted}, Updated: ${result.updated}`
561
+ );
562
+ } catch (error) {
563
+ console.error(`✗ Error saving chunk ${chunkNumber}:`, error);
564
+ throw error;
565
+ }
566
+ },
567
+ });
568
+ console.log(`✓ All chunks processed. Total jobs saved: ${totalSaved}/${updatedJobs.length}`);
569
+ }
570
+ console.log("saved jobs descriptions and location apply url to CMS successfully");//change comment
519
571
 
520
- console.log("saved jobs descriptions and location apply url to CMS successfully");
521
572
  await aggregateJobs();
522
573
  await referenceJobs();
574
+
523
575
  console.log("syncing jobs fast finished successfully");
576
+
524
577
  }
525
578
  catch (error) {
526
579
  error.message="Error syncing jobs: "+error.message;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.1313",
3
+ "version": "1.7.1314",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {