Skip to content

Commit 4b612bc

Browse files
committed
Merge remote-tracking branch 'origin/fix/transaction-issues' into fix/update-field-access-control-after-save
2 parents 28d7bc7 + 292aa60 commit 4b612bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+210
-168
lines changed

packages/db-mongodb/src/count.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ export const count: Count = async function count(
1515
) {
1616
const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })
1717

18-
const options: CountOptions = {
19-
session: await getSession(this, req),
20-
}
21-
2218
let hasNearConstraint = false
2319

2420
if (where) {
@@ -37,6 +33,10 @@ export const count: Count = async function count(
3733
// useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
3834
const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0
3935

36+
const options: CountOptions = {
37+
session: await getSession(this, req),
38+
}
39+
4040
if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
4141
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
4242
// a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,

packages/db-mongodb/src/countGlobalVersions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ export const countGlobalVersions: CountGlobalVersions = async function countGlob
1515
) {
1616
const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })
1717

18-
const options: CountOptions = {
19-
session: await getSession(this, req),
20-
}
21-
2218
let hasNearConstraint = false
2319

2420
if (where) {
@@ -36,6 +32,10 @@ export const countGlobalVersions: CountGlobalVersions = async function countGlob
3632
// useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
3733
const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0
3834

35+
const options: CountOptions = {
36+
session: await getSession(this, req),
37+
}
38+
3939
if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
4040
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
4141
// a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,

packages/db-mongodb/src/countVersions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ export const countVersions: CountVersions = async function countVersions(
1919
versions: true,
2020
})
2121

22-
const options: CountOptions = {
23-
session: await getSession(this, req),
24-
}
25-
2622
let hasNearConstraint = false
2723

2824
if (where) {
@@ -40,6 +36,10 @@ export const countVersions: CountVersions = async function countVersions(
4036
// useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
4137
const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0
4238

39+
const options: CountOptions = {
40+
session: await getSession(this, req),
41+
}
42+
4343
if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
4444
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
4545
// a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,

packages/db-mongodb/src/create.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ export const create: Create = async function create(
1515
) {
1616
const { collectionConfig, customIDType, Model } = getCollection({ adapter: this, collectionSlug })
1717

18-
const options: CreateOptions = {
19-
session: await getSession(this, req),
20-
// Timestamps are manually added by the write transform
21-
timestamps: false,
22-
}
23-
2418
let doc
2519

2620
if (!data.createdAt) {
@@ -47,6 +41,12 @@ export const create: Create = async function create(
4741
}
4842
}
4943

44+
const options: CreateOptions = {
45+
session: await getSession(this, req),
46+
// Timestamps are manually added by the write transform
47+
timestamps: false,
48+
}
49+
5050
try {
5151
;[doc] = await Model.create([data], options)
5252
} catch (error) {

packages/db-mongodb/src/createGlobalVersion.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ export const createGlobalVersion: CreateGlobalVersion = async function createGlo
2222
) {
2323
const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })
2424

25-
const options = {
26-
session: await getSession(this, req),
27-
// Timestamps are manually added by the write transform
28-
timestamps: false,
29-
}
30-
3125
const data = {
3226
autosave,
3327
createdAt,
@@ -50,6 +44,12 @@ export const createGlobalVersion: CreateGlobalVersion = async function createGlo
5044
operation: 'write',
5145
})
5246

47+
const options = {
48+
session: await getSession(this, req),
49+
// Timestamps are manually added by the write transform
50+
timestamps: false,
51+
}
52+
5353
let [doc] = await Model.create([data], options, req)
5454

5555
await Model.updateMany(

packages/db-mongodb/src/createVersion.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ export const createVersion: CreateVersion = async function createVersion(
2727
versions: true,
2828
})
2929

30-
const options = {
31-
session: await getSession(this, req),
32-
// Timestamps are manually added by the write transform
33-
timestamps: false,
34-
}
35-
3630
const data = {
3731
autosave,
3832
createdAt,
@@ -56,6 +50,12 @@ export const createVersion: CreateVersion = async function createVersion(
5650
operation: 'write',
5751
})
5852

53+
const options = {
54+
session: await getSession(this, req),
55+
// Timestamps are manually added by the write transform
56+
timestamps: false,
57+
}
58+
5959
let [doc] = await Model.create([data], options, req)
6060

6161
const parentQuery = {

packages/db-mongodb/src/deleteMany.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ export const deleteMany: DeleteMany = async function deleteMany(
1414
) {
1515
const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })
1616

17-
const options: DeleteOptions = {
18-
session: await getSession(this, req),
19-
}
20-
2117
const query = await buildQuery({
2218
adapter: this,
2319
collectionSlug,
2420
fields: collectionConfig.flattenedFields,
2521
where,
2622
})
2723

24+
const options: DeleteOptions = {
25+
session: await getSession(this, req),
26+
}
27+
2828
await Model.deleteMany(query, options)
2929
}

packages/db-mongodb/src/deleteOne.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ export const deleteOne: DeleteOne = async function deleteOne(
1515
) {
1616
const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })
1717

18+
const query = await buildQuery({
19+
adapter: this,
20+
collectionSlug,
21+
fields: collectionConfig.flattenedFields,
22+
where,
23+
})
24+
1825
const options: MongooseUpdateQueryOptions = {
1926
projection: buildProjectionFromSelect({
2027
adapter: this,
@@ -24,13 +31,6 @@ export const deleteOne: DeleteOne = async function deleteOne(
2431
session: await getSession(this, req),
2532
}
2633

27-
const query = await buildQuery({
28-
adapter: this,
29-
collectionSlug,
30-
fields: collectionConfig.flattenedFields,
31-
where,
32-
})
33-
3434
if (returning === false) {
3535
await Model.deleteOne(query, options)?.lean()
3636
return null

packages/db-mongodb/src/deleteVersions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ export const deleteVersions: DeleteVersions = async function deleteVersions(
3636
throw new APIError('Either collection or globalSlug must be passed.')
3737
}
3838

39-
const session = await getSession(this, req)
40-
4139
const query = await buildQuery({
4240
adapter: this,
4341
fields,
4442
locale,
4543
where,
4644
})
4745

46+
const session = await getSession(this, req)
47+
4848
await VersionsModel.deleteMany(query, { session })
4949
}

packages/db-mongodb/src/find.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ export const find: Find = async function find(
3434
) {
3535
const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })
3636

37-
const session = await getSession(this, req)
38-
3937
let hasNearConstraint = false
4038

4139
if (where) {
@@ -66,6 +64,8 @@ export const find: Find = async function find(
6664
where,
6765
})
6866

67+
const session = await getSession(this, req)
68+
6969
// useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
7070
const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0
7171
const paginationOptions: PaginateOptions = {

0 commit comments

Comments
 (0)