Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple small fixes #38

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@
<isprint value="${Resource.msg('algolia.label.sentsuccessfully', 'algolia', null)}" encoding="htmlcontent" />
</td>
<td class="table_detail e s" width="100%">
<isprint value="${logData.category.sendedChunk + ' chunk (' + logData.category.sendedRecords + ' records)'}" encoding="htmlcontent" />
<isprint value="${logData.category.sentChunks + ' chunks (' + logData.category.sentRecords + ' records)'}" encoding="htmlcontent" />
</td>
</tr>
<tr>
<td class="table_detail w e s" nowrap="nowrap">
<isprint value="${Resource.msg('algolia.label.sentfailed', 'algolia', null)}" encoding="htmlcontent" />
</td>
<td class="table_detail e s" width="100%">
<isprint value="${logData.category.failedChunk + ' chunk (' + logData.category.failedRecords + ' records)'}" encoding="htmlcontent" />
<isprint value="${logData.category.failedChunks + ' chunks (' + logData.category.failedRecords + ' records)'}" encoding="htmlcontent" />
</td>
</tr>
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@
<isprint value="${Resource.msg('algolia.label.sentsuccessfully', 'algolia', null)}" encoding="htmlcontent" />
</td>
<td class="table_detail e s" width="100%">
<isprint value="${logData.product.sendedChunk + ' chunk (' + logData.product.sendedRecords + ' records)'}" encoding="htmlcontent" />
<isprint value="${logData.product.sentChunks + ' chunks (' + logData.product.sentRecords + ' records)'}" encoding="htmlcontent" />
</td>
</tr>
<tr>
<td class="table_detail w e s" nowrap="nowrap">
<isprint value="${Resource.msg('algolia.label.sentfailed', 'algolia', null)}" encoding="htmlcontent" />
</td>
<td class="table_detail e s" width="100%">
<isprint value="${logData.product.failedChunk + ' chunk (' + logData.product.failedRecords + ' records)'}" encoding="htmlcontent" />
<isprint value="${logData.product.failedChunks + ' chunks (' + logData.product.failedRecords + ' records)'}" encoding="htmlcontent" />
</td>
</tr>
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ algolia.label.errmessage=Error Message:
algolia.label.lastsentdate=Last sent Date
algolia.label.sentsuccessfully=Data sent successfully
algolia.label.sentfailed=Failed to send data
algolia.label.category.title.processed=Log of the last processed Categories data
algolia.label.category.title.sent=Log of the last sent Category data
algolia.label.category.title.processed=Category export - last processed
algolia.label.category.title.sent=Category export - last sent
algolia.label.category.processed=Categories processed
algolia.label.category.toupdate=Categories ready for update
algolia.label.product.title.processed=Log of the last processed Products data
algolia.label.product.title.sent=Log of the last sent Product data
algolia.label.product.title.processed=Product export - last processed
algolia.label.product.title.sent=Product export - last sent
algolia.label.product.processed=Products processed
algolia.label.product.toupdate=Products ready for update
algolia.label.preference.name=Preference Name
Expand All @@ -29,7 +29,7 @@ algolia.label.preference.baseurl=Read Host Base Url
algolia.label.preference.instock=InStock Threshold
algolia.label.preference.custom=Custom Fields
algolia.label.preference.indexprefix=Index Prefix. If set, it replaces the default index prefix: < hostname >__< siteID >
algolia.label.preference.enablessr=Enable server-side rendering for CLP (category landing page) results. Improves SEO but minimally increases page load times.
algolia.label.preference.enablessr=Enable server-side rendering for CLP (category landing page) results. Improves SEO but slightly increases page load times.
algolia.label.preference.clientid=OCAPI Client ID
algolia.label.preference.clientpassword=OCAPI Client password
algolia.label.button.apply=Apply
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ function LogJob() {
this.sendDate = '---';
this.sendError = false;
this.sendErrorMessage = '';
this.sendedChunk = 0;
this.sendedRecords = 0;
this.failedChunk = 0;
this.sentChunks = 0;
this.sentRecords = 0;
this.failedChunks = 0;
this.failedRecords = 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ function sendDelta(deltaList, logID, parameters) {
sendLogData.sendDate = algoliaData.getLocalDateTime(new Date());
sendLogData.sendError = true;
sendLogData.sendErrorMessage = '';
sendLogData.sendedChunk = 0;
sendLogData.sendedRecords = 0;
sendLogData.failedChunk = 0;
sendLogData.sentChunks = 0;
sendLogData.sentRecords = 0;
sendLogData.failedChunks = 0;
sendLogData.failedRecords = 0;

var entries = [];
var failedChunks = [];
var countFailedShunks = 0;
var countFailedChunks = 0;

var status = new Status(Status.OK);

Expand All @@ -79,10 +79,10 @@ function sendDelta(deltaList, logID, parameters) {
var inputMaxNumberOfEntries = Object.hasOwnProperty.call(parameters, 'maxNumberOfEntries') ? parseInt(parameters.maxNumberOfEntries, 10) : MAX_CHUNKS_SIZE;

// calculate it
var calkMaxNumberOfEntries = Math.floor(QUOTA_API_JS_JSON_STRING_LENGTH / deltaList.getRecordSize()); // number of objects to fit the quota
calkMaxNumberOfEntries -= Math.floor(calkMaxNumberOfEntries / 5); // reduce by 20%
var calcMaxNumberOfEntries = Math.floor(QUOTA_API_JS_JSON_STRING_LENGTH / deltaList.getRecordSize()); // number of objects to fit the quota
calcMaxNumberOfEntries -= Math.floor(calcMaxNumberOfEntries / 5); // reduce by 20%

var maxNumberOfEntries = Math.min(inputMaxNumberOfEntries, calkMaxNumberOfEntries);
var maxNumberOfEntries = Math.min(inputMaxNumberOfEntries, calcMaxNumberOfEntries);

while (deltaList.hasNext()) {
entries.push(deltaList.next());
Expand All @@ -92,21 +92,21 @@ function sendDelta(deltaList, logID, parameters) {
status = sendChunk(entries);
if (status.error) {
failedChunks = failedChunks.concat(entries);
countFailedShunks += 1;
sendLogData.failedChunk += 1;
countFailedChunks += 1;
sendLogData.failedChunks += 1;
sendLogData.failedRecords += entries.length;
sendLogData.sendErrorMessage = status.details.errorMessage ? status.details.errorMessage : 'Error sending chunk. See the log file for details.';

if (countFailedShunks > MAX_FAILED_CHUNKS) {
if (countFailedChunks > MAX_FAILED_CHUNKS) {
sendLogData.sendError = true;
sendLogData.sendErrorMessage = 'Too many failed chunks. Service might be down. Aborting the job.';
algoliaData.setLogData(logID, sendLogData);
deltaList.close();
return status;
}
} else {
sendLogData.sendedChunk += 1;
sendLogData.sendedRecords += entries.length;
sendLogData.sentChunks += 1;
sendLogData.sentRecords += entries.length;
}
entries.length = 0; // crear the array
}
Expand All @@ -122,17 +122,17 @@ function sendDelta(deltaList, logID, parameters) {
sendLogData.sendErrorMessage = status.details.errorMessage ? status.details.errorMessage : 'Error sending chunk. See the log file for details.';
} else {
sendLogData.sendError = false;
sendLogData.sendedChunk += sendLogData.failedChunk;
sendLogData.sendedRecords += sendLogData.failedRecords;
sendLogData.failedChunk = 0;
sendLogData.sentChunks += sendLogData.failedChunks;
sendLogData.sentRecords += sendLogData.failedRecords;
sendLogData.failedChunks = 0;
sendLogData.failedRecords = 0;
}

sendLogData.sendDate = algoliaData.getLocalDateTime(new Date());
algoliaData.setLogData(logID, sendLogData);

logger.info('Chunk(s) sent: {0}; Failed chunk(s): {1}\nRecord(s) sent: {2}; Failed record(s): {3}',
sendLogData.sendedChunk, sendLogData.failedChunk, sendLogData.sendedRecords, sendLogData.failedRecords);
logger.info('Chunks sent: {0}; Failed chunks: {1}\nRecords sent: {2}; Failed records: {3}',
sendLogData.sentChunks, sendLogData.failedChunks, sendLogData.sentRecords, sendLogData.failedRecords);

return status;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ function runCategoryExport(parameters) {
? siteRootCategory.getOnlineSubCategories().iterator() : null;
var listOfCategories = [];

var categoryLogData = algoliaData.getLogData('LastCategorySyncLog');
const updateLogType = 'LastCategorySyncLog';

var categoryLogData = algoliaData.getLogData(updateLogType);
categoryLogData.processedDate = algoliaData.getLocalDateTime(new Date());
categoryLogData.processedError = true;
categoryLogData.processedErrorMessage = '';
Expand All @@ -240,7 +242,7 @@ function runCategoryExport(parameters) {
if (!algoliaData.getPreference('Enable')) {
jobHelper.logFileError('Disable', 'Algolia Cartridge Disabled', status);
categoryLogData.processedErrorMessage = 'Algolia Cartridge Disabled';
algoliaData.setLogData('LastCategorySyncLog', categoryLogData);
algoliaData.setLogData(updateLogType, categoryLogData);
return status;
}

Expand All @@ -266,7 +268,7 @@ function runCategoryExport(parameters) {
} catch (error) {
jobHelper.logFileError(snapshotFile.fullPath, 'Error remove snapshot file', error);
categoryLogData.processedErrorMessage = 'Error remove shapnshot file';
algoliaData.setLogData('LastCategorySyncLog', categoryLogData);
algoliaData.setLogData(updateLogType, categoryLogData);
return new Status(Status.ERROR);
}
}
Expand Down Expand Up @@ -370,7 +372,7 @@ function runCategoryExport(parameters) {
categoryLogData.processedErrorMessage = '';
categoryLogData.processedRecords = counterCategoriesTotal;
categoryLogData.processedToUpdateRecords = counterCategoriesForUpdate;
algoliaData.setLogData('LastCategorySyncLog', categoryLogData);
algoliaData.setLogData(updateLogType, categoryLogData);

return new Status(Status.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ function runProductExport(parameters) {
var algoliaData = require('*/cartridge/scripts/algolia/lib/algoliaData');
var fileReadIterator = require('*/cartridge/scripts/algolia/helper/fileReadIterator');

const updateLogType = 'LastProductSyncLog';

var counterProductsTotal = 0;
var counterProductsForUpdate = 0;
var productLogData = algoliaData.getLogData('LastProductSyncLog');
var productLogData = algoliaData.getLogData(updateLogType);
productLogData.processedDate = algoliaData.getLocalDateTime(new Date());
productLogData.processedError = true;
productLogData.processedErrorMessage = '';
Expand All @@ -96,7 +98,7 @@ function runProductExport(parameters) {
if (!algoliaData.getPreference('Enable')) {
jobHelper.logFileError('Disable', 'Algolia Cartridge Disabled', status);
productLogData.processedErrorMessage = 'Algolia Cartridge Disabled';
algoliaData.setLogData('LastProductSyncLog', productLogData);
algoliaData.setLogData(updateLogType, productLogData);
return status;
}

Expand Down Expand Up @@ -129,7 +131,7 @@ function runProductExport(parameters) {
} catch (error) {
jobHelper.logFileError(updateFile.fullPath, 'Error open Delta file to write', error);
productLogData.processedErrorMessage = 'Error open Delta file to write';
algoliaData.setLogData('LastProductSyncLog', productLogData);
algoliaData.setLogData(updateLogType, productLogData);
snapshotFileWriter.close();
snapshotXmlWriter.close();
return new Status(Status.ERROR);
Expand All @@ -145,7 +147,7 @@ function runProductExport(parameters) {
} catch (error) {
jobHelper.logFileError(snapshotFile.fullPath, 'Error remove file', error);
productLogData.processedErrorMessage = 'Error remove file';
algoliaData.setLogData('LastProductSyncLog', productLogData);
algoliaData.setLogData(updateLogType, productLogData);
snapshotFileWriter.close();
snapshotXmlWriter.close();
updateFileWriter.close();
Expand All @@ -156,7 +158,7 @@ function runProductExport(parameters) {
snapshotReadIterator = fileReadIterator.create(algoliaConstants.SNAPSHOT_PRODUCTS_FILE_NAME, 'product');
if (empty(snapshotReadIterator)) {
productLogData.processedErrorMessage = 'Error open Snapshot file or read';
algoliaData.setLogData('LastProductSyncLog', productLogData);
algoliaData.setLogData(updateLogType, productLogData);
snapshotFileWriter.close();
snapshotXmlWriter.close();
updateFileWriter.close();
Expand All @@ -181,7 +183,7 @@ function runProductExport(parameters) {
} catch (error) {
jobHelper.logFileError(newSnapshotFile.fullPath, 'Error write to file', error);
productLogData.processedErrorMessage = 'Error write to file';
algoliaData.setLogData('LastProductSyncLog', productLogData);
algoliaData.setLogData(updateLogType, productLogData);
snapshotFileWriter.close();
snapshotXmlWriter.close();
updateFileWriter.close();
Expand Down Expand Up @@ -258,7 +260,7 @@ function runProductExport(parameters) {
} catch (error) {
jobHelper.logFileError(updateFile.fullPath, 'Error write to file', error);
productLogData.processedErrorMessage = 'Error write to file';
algoliaData.setLogData('LastProductSyncLog', productLogData);
algoliaData.setLogData(updateLogType, productLogData);
snapshotFileWriter.close();
snapshotXmlWriter.close();
updateFileWriter.close();
Expand Down Expand Up @@ -300,7 +302,7 @@ function runProductExport(parameters) {
productLogData.processedErrorMessage = '';
productLogData.processedRecords = counterProductsTotal;
productLogData.processedToUpdateRecords = counterProductsForUpdate;
algoliaData.setLogData('LastProductSyncLog', productLogData);
algoliaData.setLogData(updateLogType, productLogData);

return new Status(Status.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function enableAutocomplete(config) {
return html`
<div class="text-truncate text-nowrap">
<img class="swatch-circle hidden-xs-down" src=${item.firstImage.dis_base_link}></img>
<a href=${newURL}>${components.Highlight({ hit: item, attribute: "name", tagName: "em" })}</a>
<a href="${newURL.href}">${components.Highlight({ hit: item, attribute: "name", tagName: "em" })}</a>
</div>`;
},
},
Expand Down