Files
klz-cables.com/.pnpm-store/v10/files/f8/99f7abcb866284b617d57d5a90ac41a63151c1fdfea7798fcac8e40446c7c9d28d8587bd34ed1df49acbc44c6f64dcff9b768200d36242ccbb7d23a27daee9
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

63 lines
2.8 KiB
Plaintext

/**
* Checks whether we should use the upsertRow function for the passed data and otherwise use a simple SQL SET call.
* We need to use upsertRow only when the data has arrays, blocks, hasMany select/text/number, localized fields, complex relationships.
*/ export const shouldUseOptimizedUpsertRow = ({ data, fields })=>{
let fieldsMatched = false;
for(const key in data){
const value = data[key];
const field = fields.find((each)=>each.name === key);
if (!field) {
continue;
}
fieldsMatched = true;
if (field.type === 'blocks' || (field.type === 'text' || field.type === 'relationship' || field.type === 'upload' || field.type === 'select' || field.type === 'number') && field.hasMany || (field.type === 'relationship' || field.type === 'upload') && Array.isArray(field.relationTo) || field.localized) {
return false;
}
if (field.type === 'array') {
if (typeof value === 'object' && '$push' in value && value.$push) {
return shouldUseOptimizedUpsertRow({
// Only check first row - this function cares about field definitions. Each array row will have the same field definitions.
data: Array.isArray(value.$push) ? value.$push?.[0] : value.$push,
fields: field.flattenedFields
});
}
return false;
}
// Handle relationship $push and $remove operations
if ((field.type === 'relationship' || field.type === 'upload') && field.hasMany) {
if (typeof value === 'object' && ('$push' in value || '$remove' in value)) {
return false // Use full upsertRow for relationship operations
;
}
}
if ((field.type === 'group' || field.type === 'tab') && value && typeof value === 'object' && !shouldUseOptimizedUpsertRow({
data: value,
fields: field.flattenedFields
})) {
return false;
}
}
// Handle dot-notation paths when no fields matched
if (!fieldsMatched) {
for(const key in data){
if (key.includes('.')) {
// Split on first dot only
const firstDotIndex = key.indexOf('.');
const fieldName = key.substring(0, firstDotIndex);
const remainingPath = key.substring(firstDotIndex + 1);
const nestedData = {
[fieldName]: {
[remainingPath]: data[key]
}
};
return shouldUseOptimizedUpsertRow({
data: nestedData,
fields
});
}
}
}
return true;
};
//# sourceMappingURL=shouldUseOptimizedUpsertRow.js.map