Files
klz-cables.com/.pnpm-store/v10/files/8a/29e81804b73322e5a378b122d03c3fe713f067038d4feae05c9fe005e0228a0d25493558b638cf8a239257030bae6a6661516d0423bdc44d67f6afa40c184e
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

83 lines
2.7 KiB
Plaintext

import toSnakeCase from 'to-snake-case';
import { findMany } from './find/findMany.js';
import { upsertRow } from './upsertRow/index.js';
import { shouldUseOptimizedUpsertRow } from './upsertRow/shouldUseOptimizedUpsertRow.js';
import { getTransaction } from './utilities/getTransaction.js';
export const updateJobs = async function updateMany({ id, data, limit: limitArg, req, returning, sort: sortArg, where: whereArg }) {
if (!data?.log?.length && !(data.log && typeof data.log === 'object' && '$push' in data.log)) {
delete data.log;
}
const whereToUse = id ? {
id: {
equals: id
}
} : whereArg;
const limit = id ? 1 : limitArg;
const collection = this.payload.collections['payload-jobs'].config;
const tableName = this.tableNameMap.get(toSnakeCase(collection.slug));
const sort = sortArg !== undefined && sortArg !== null ? sortArg : collection.defaultSort;
const useOptimizedUpsertRow = shouldUseOptimizedUpsertRow({
data,
fields: collection.flattenedFields
});
if (useOptimizedUpsertRow && id) {
const db = await getTransaction(this, req);
const result = await upsertRow({
id,
adapter: this,
collectionSlug: 'payload-jobs',
data,
db,
fields: collection.flattenedFields,
ignoreResult: returning === false,
operation: 'update',
req,
tableName
});
return returning === false ? null : [
result
];
}
const jobs = await findMany({
adapter: this,
collectionSlug: 'payload-jobs',
fields: collection.flattenedFields,
limit: id ? 1 : limit,
pagination: false,
req,
sort,
tableName,
where: whereToUse
});
if (!jobs.docs.length) {
return [];
}
const db = await getTransaction(this, req);
const results = [];
// TODO: We need to batch this to reduce the amount of db calls. This can get very slow if we are updating a lot of rows.
for (const job of jobs.docs){
const updateData = useOptimizedUpsertRow ? data : {
...job,
...data
};
const result = await upsertRow({
id: job.id,
adapter: this,
collectionSlug: 'payload-jobs',
data: updateData,
db,
fields: collection.flattenedFields,
ignoreResult: returning === false,
operation: 'update',
req,
tableName
});
results.push(result);
}
if (returning === false) {
return null;
}
return results;
};
//# sourceMappingURL=updateJobs.js.map