@payloadcms/drizzle 3.80.0-canary.2 → 3.80.0-internal.c396c15
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.
- package/dist/updateJobs.d.ts.map +1 -1
- package/dist/updateJobs.js +49 -3
- package/dist/updateJobs.js.map +1 -1
- package/package.json +3 -3
package/dist/updateJobs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateJobs.d.ts","sourceRoot":"","sources":["../src/updateJobs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAS,MAAM,SAAS,CAAA;AAWhD,eAAO,MAAM,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"updateJobs.d.ts","sourceRoot":"","sources":["../src/updateJobs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAS,MAAM,SAAS,CAAA;AAWhD,eAAO,MAAM,UAAU,EAAE,UA0IxB,CAAA"}
|
package/dist/updateJobs.js
CHANGED
|
@@ -3,7 +3,17 @@ import { findMany } from './find/findMany.js';
|
|
|
3
3
|
import { upsertRow } from './upsertRow/index.js';
|
|
4
4
|
import { shouldUseOptimizedUpsertRow } from './upsertRow/shouldUseOptimizedUpsertRow.js';
|
|
5
5
|
import { getTransaction } from './utilities/getTransaction.js';
|
|
6
|
-
export const updateJobs = async function updateMany({ id, data, limit: limitArg, req, returning, sort: sortArg, where: whereArg }) {
|
|
6
|
+
export const updateJobs = async function updateMany({ id, data, debugID, limit: limitArg, req, returning, sort: sortArg, where: whereArg }) {
|
|
7
|
+
const prefix = debugID ? `[${debugID}] drizzle.updateJobs` : null;
|
|
8
|
+
const t0 = prefix ? Date.now() : 0;
|
|
9
|
+
if (prefix) {
|
|
10
|
+
console.log(`${prefix} - enter`, {
|
|
11
|
+
id,
|
|
12
|
+
limit: limitArg,
|
|
13
|
+
returning,
|
|
14
|
+
sort: sortArg
|
|
15
|
+
});
|
|
16
|
+
}
|
|
7
17
|
if (!data?.log?.length && !(data.log && typeof data.log === 'object' && '$push' in data.log)) {
|
|
8
18
|
delete data.log;
|
|
9
19
|
}
|
|
@@ -20,8 +30,16 @@ export const updateJobs = async function updateMany({ id, data, limit: limitArg,
|
|
|
20
30
|
data,
|
|
21
31
|
fields: collection.flattenedFields
|
|
22
32
|
});
|
|
33
|
+
if (prefix) {
|
|
34
|
+
console.log(`${prefix} - useOptimizedUpsertRow: ${useOptimizedUpsertRow}, tableName: ${tableName}`);
|
|
35
|
+
}
|
|
23
36
|
if (useOptimizedUpsertRow && id) {
|
|
37
|
+
let ts = Date.now();
|
|
24
38
|
const db = await getTransaction(this, req);
|
|
39
|
+
if (prefix) {
|
|
40
|
+
console.log(`${prefix} - getTransaction (optimized path) took ${Date.now() - ts}ms`);
|
|
41
|
+
}
|
|
42
|
+
ts = Date.now();
|
|
25
43
|
const result = await upsertRow({
|
|
26
44
|
id,
|
|
27
45
|
adapter: this,
|
|
@@ -34,10 +52,21 @@ export const updateJobs = async function updateMany({ id, data, limit: limitArg,
|
|
|
34
52
|
req,
|
|
35
53
|
tableName
|
|
36
54
|
});
|
|
55
|
+
if (prefix) {
|
|
56
|
+
console.log(`${prefix} - upsertRow (optimized, single) took ${Date.now() - ts}ms, total ${Date.now() - t0}ms`);
|
|
57
|
+
}
|
|
37
58
|
return returning === false ? null : [
|
|
38
59
|
result
|
|
39
60
|
];
|
|
40
61
|
}
|
|
62
|
+
let ts = prefix ? Date.now() : 0;
|
|
63
|
+
if (prefix) {
|
|
64
|
+
console.log(`${prefix} - calling findMany`, {
|
|
65
|
+
limit: id ? 1 : limit,
|
|
66
|
+
sort,
|
|
67
|
+
where: whereToUse
|
|
68
|
+
});
|
|
69
|
+
}
|
|
41
70
|
const jobs = await findMany({
|
|
42
71
|
adapter: this,
|
|
43
72
|
collectionSlug: 'payload-jobs',
|
|
@@ -49,17 +78,28 @@ export const updateJobs = async function updateMany({ id, data, limit: limitArg,
|
|
|
49
78
|
tableName,
|
|
50
79
|
where: whereToUse
|
|
51
80
|
});
|
|
81
|
+
if (prefix) {
|
|
82
|
+
console.log(`${prefix} - findMany took ${Date.now() - ts}ms, found ${jobs.docs.length} docs`);
|
|
83
|
+
}
|
|
52
84
|
if (!jobs.docs.length) {
|
|
85
|
+
if (prefix) {
|
|
86
|
+
console.log(`${prefix} - no docs found, returning [], total ${Date.now() - t0}ms`);
|
|
87
|
+
}
|
|
53
88
|
return [];
|
|
54
89
|
}
|
|
90
|
+
ts = prefix ? Date.now() : 0;
|
|
55
91
|
const db = await getTransaction(this, req);
|
|
92
|
+
if (prefix) {
|
|
93
|
+
console.log(`${prefix} - getTransaction took ${Date.now() - ts}ms`);
|
|
94
|
+
}
|
|
56
95
|
const results = [];
|
|
57
|
-
|
|
58
|
-
|
|
96
|
+
for(let i = 0; i < jobs.docs.length; i++){
|
|
97
|
+
const job = jobs.docs[i];
|
|
59
98
|
const updateData = useOptimizedUpsertRow ? data : {
|
|
60
99
|
...job,
|
|
61
100
|
...data
|
|
62
101
|
};
|
|
102
|
+
ts = prefix ? Date.now() : 0;
|
|
63
103
|
const result = await upsertRow({
|
|
64
104
|
id: job.id,
|
|
65
105
|
adapter: this,
|
|
@@ -72,8 +112,14 @@ export const updateJobs = async function updateMany({ id, data, limit: limitArg,
|
|
|
72
112
|
req,
|
|
73
113
|
tableName
|
|
74
114
|
});
|
|
115
|
+
if (prefix) {
|
|
116
|
+
console.log(`${prefix} - upsertRow [${i + 1}/${jobs.docs.length}] id=${job.id} took ${Date.now() - ts}ms`);
|
|
117
|
+
}
|
|
75
118
|
results.push(result);
|
|
76
119
|
}
|
|
120
|
+
if (prefix) {
|
|
121
|
+
console.log(`${prefix} - all upserts done, total ${Date.now() - t0}ms`);
|
|
122
|
+
}
|
|
77
123
|
if (returning === false) {
|
|
78
124
|
return null;
|
|
79
125
|
}
|
package/dist/updateJobs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateJobs.ts"],"sourcesContent":["import type { UpdateJobs, Where } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\nimport { upsertRow } from './upsertRow/index.js'\nimport { shouldUseOptimizedUpsertRow } from './upsertRow/shouldUseOptimizedUpsertRow.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const updateJobs: UpdateJobs = async function updateMany(\n this: DrizzleAdapter,\n { id, data, limit: limitArg, req, returning, sort: sortArg, where: whereArg },\n) {\n if (\n !(data?.log as object[])?.length &&\n !(data.log && typeof data.log === 'object' && '$push' in data.log)\n ) {\n delete data.log\n }\n\n const whereToUse: Where = id ? { id: { equals: id } } : whereArg\n const limit = id ? 1 : limitArg\n\n const collection = this.payload.collections['payload-jobs'].config\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n const sort = sortArg !== undefined && sortArg !== null ? sortArg : collection.defaultSort\n\n const useOptimizedUpsertRow = shouldUseOptimizedUpsertRow({\n data,\n fields: collection.flattenedFields,\n })\n\n if (useOptimizedUpsertRow && id) {\n const db = await getTransaction(this, req)\n\n const result = await upsertRow({\n id,\n adapter: this,\n collectionSlug: 'payload-jobs',\n data,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n operation: 'update',\n req,\n tableName,\n })\n\n return returning === false ? null : [result]\n }\n\n const jobs = await findMany({\n adapter: this,\n collectionSlug: 'payload-jobs',\n fields: collection.flattenedFields,\n limit: id ? 1 : limit,\n pagination: false,\n req,\n sort,\n tableName,\n where: whereToUse,\n })\n if (!jobs.docs.length) {\n return []\n }\n\n const db = await getTransaction(this, req)\n\n const results = []\n\n
|
|
1
|
+
{"version":3,"sources":["../src/updateJobs.ts"],"sourcesContent":["import type { UpdateJobs, Where } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\nimport { upsertRow } from './upsertRow/index.js'\nimport { shouldUseOptimizedUpsertRow } from './upsertRow/shouldUseOptimizedUpsertRow.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const updateJobs: UpdateJobs = async function updateMany(\n this: DrizzleAdapter,\n { id, data, debugID, limit: limitArg, req, returning, sort: sortArg, where: whereArg },\n) {\n const prefix = debugID ? `[${debugID}] drizzle.updateJobs` : null\n const t0 = prefix ? Date.now() : 0\n\n if (prefix) {\n console.log(`${prefix} - enter`, { id, limit: limitArg, returning, sort: sortArg })\n }\n\n if (\n !(data?.log as object[])?.length &&\n !(data.log && typeof data.log === 'object' && '$push' in data.log)\n ) {\n delete data.log\n }\n\n const whereToUse: Where = id ? { id: { equals: id } } : whereArg\n const limit = id ? 1 : limitArg\n\n const collection = this.payload.collections['payload-jobs'].config\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n const sort = sortArg !== undefined && sortArg !== null ? sortArg : collection.defaultSort\n\n const useOptimizedUpsertRow = shouldUseOptimizedUpsertRow({\n data,\n fields: collection.flattenedFields,\n })\n\n if (prefix) {\n console.log(\n `${prefix} - useOptimizedUpsertRow: ${useOptimizedUpsertRow}, tableName: ${tableName}`,\n )\n }\n\n if (useOptimizedUpsertRow && id) {\n let ts = Date.now()\n const db = await getTransaction(this, req)\n if (prefix) {\n console.log(`${prefix} - getTransaction (optimized path) took ${Date.now() - ts}ms`)\n }\n\n ts = Date.now()\n const result = await upsertRow({\n id,\n adapter: this,\n collectionSlug: 'payload-jobs',\n data,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n operation: 'update',\n req,\n tableName,\n })\n if (prefix) {\n console.log(\n `${prefix} - upsertRow (optimized, single) took ${Date.now() - ts}ms, total ${Date.now() - t0}ms`,\n )\n }\n\n return returning === false ? null : [result]\n }\n\n let ts = prefix ? Date.now() : 0\n if (prefix) {\n console.log(`${prefix} - calling findMany`, { limit: id ? 1 : limit, sort, where: whereToUse })\n }\n const jobs = await findMany({\n adapter: this,\n collectionSlug: 'payload-jobs',\n fields: collection.flattenedFields,\n limit: id ? 1 : limit,\n pagination: false,\n req,\n sort,\n tableName,\n where: whereToUse,\n })\n if (prefix) {\n console.log(`${prefix} - findMany took ${Date.now() - ts}ms, found ${jobs.docs.length} docs`)\n }\n if (!jobs.docs.length) {\n if (prefix) {\n console.log(`${prefix} - no docs found, returning [], total ${Date.now() - t0}ms`)\n }\n return []\n }\n\n ts = prefix ? Date.now() : 0\n const db = await getTransaction(this, req)\n if (prefix) {\n console.log(`${prefix} - getTransaction took ${Date.now() - ts}ms`)\n }\n\n const results = []\n\n for (let i = 0; i < jobs.docs.length; i++) {\n const job = jobs.docs[i]\n const updateData = useOptimizedUpsertRow\n ? data\n : {\n ...job,\n ...data,\n }\n\n ts = prefix ? Date.now() : 0\n const result = await upsertRow({\n id: job.id,\n adapter: this,\n collectionSlug: 'payload-jobs',\n data: updateData,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n operation: 'update',\n req,\n tableName,\n })\n if (prefix) {\n console.log(\n `${prefix} - upsertRow [${i + 1}/${jobs.docs.length}] id=${job.id} took ${Date.now() - ts}ms`,\n )\n }\n\n results.push(result)\n }\n\n if (prefix) {\n console.log(`${prefix} - all upserts done, total ${Date.now() - t0}ms`)\n }\n\n if (returning === false) {\n return null\n }\n\n return results\n}\n"],"names":["toSnakeCase","findMany","upsertRow","shouldUseOptimizedUpsertRow","getTransaction","updateJobs","updateMany","id","data","debugID","limit","limitArg","req","returning","sort","sortArg","where","whereArg","prefix","t0","Date","now","console","log","length","whereToUse","equals","collection","payload","collections","config","tableName","tableNameMap","get","slug","undefined","defaultSort","useOptimizedUpsertRow","fields","flattenedFields","ts","db","result","adapter","collectionSlug","ignoreResult","operation","jobs","pagination","docs","results","i","job","updateData","push"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAC7C,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,2BAA2B,QAAQ,6CAA4C;AAC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6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/drizzle",
|
|
3
|
-
"version": "3.80.0-
|
|
3
|
+
"version": "3.80.0-internal.c396c15",
|
|
4
4
|
"description": "A library of shared functions used by different payload database adapters",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"@types/pg": "8.10.2",
|
|
61
61
|
"@types/to-snake-case": "1.0.0",
|
|
62
62
|
"@payloadcms/eslint-config": "3.28.0",
|
|
63
|
-
"payload": "3.80.0-
|
|
63
|
+
"payload": "3.80.0-internal.c396c15"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"payload": "3.80.0-
|
|
66
|
+
"payload": "3.80.0-internal.c396c15"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"build": "pnpm build:swc && pnpm build:types",
|