chore: properly isolates req in parallel requests

This commit is contained in:
James
2024-04-04 18:00:37 -04:00
parent 31cd663ad5
commit 96012b26b7
4 changed files with 102 additions and 124 deletions

View File

@@ -31,7 +31,7 @@ import { GlobalGroup1A } from './globals/Group1A.js'
import { GlobalGroup1B } from './globals/Group1B.js'
import { GlobalHidden } from './globals/Hidden.js'
import { GlobalNoApiView } from './globals/NoApiView.js'
import { clearAndSeedEverything } from './seed.js'
import { seed } from './seed.js'
import { customNestedViewPath, customParamViewPath, customViewPath } from './shared.js'
export default buildConfigWithDefaults({
@@ -129,7 +129,7 @@ export default buildConfigWithDefaults({
},
onInit: async (payload) => {
if (process.env.SEED_IN_CONFIG_ONINIT !== 'false') {
await clearAndSeedEverything(payload)
await seed(payload)
}
},
})

View File

@@ -14,102 +14,104 @@ import {
usersCollectionSlug,
} from './slugs.js'
export async function clearAndSeedEverything(_payload: Payload, parallel: boolean = false) {
export const seed = async (_payload) => {
await executePromises(
[
() =>
_payload.create({
collection: usersCollectionSlug,
data: {
email: devUser.email,
password: devUser.password,
},
depth: 0,
overrideAccess: true,
}),
...[...Array(11)].map(
() => () =>
_payload.create({
collection: postsCollectionSlug,
data: {
title: 'Title',
description: 'Description',
},
depth: 0,
overrideAccess: true,
}),
),
() =>
_payload.create({
collection: customViews1CollectionSlug,
data: {
title: 'Custom View',
},
depth: 0,
overrideAccess: true,
}),
() =>
_payload.create({
collection: customViews2CollectionSlug,
data: {
title: 'Custom View',
},
depth: 0,
overrideAccess: true,
}),
() =>
_payload.create({
collection: geoCollectionSlug,
data: {
point: [7, -7],
},
depth: 0,
overrideAccess: true,
}),
() =>
_payload.create({
collection: geoCollectionSlug,
data: {
point: [5, -5],
},
depth: 0,
overrideAccess: true,
}),
() =>
_payload.create({
collection: noApiViewCollectionSlug,
data: {},
depth: 0,
overrideAccess: true,
}),
() =>
_payload.create({
collection: 'customIdTab',
data: {
id: customIdCollectionId,
title: 'Hello world title',
},
depth: 0,
overrideAccess: true,
}),
() =>
_payload.create({
collection: 'customIdRow',
data: {
id: customIdCollectionId,
title: 'Hello world title',
},
depth: 0,
overrideAccess: true,
}),
],
false,
)
}
export async function clearAndSeedEverything(_payload: Payload) {
return await seedDB({
snapshotKey: 'adminTest',
collectionSlugs,
_payload,
seedFunction: async (_payload) => {
await executePromises(
[
() =>
_payload.create({
collection: usersCollectionSlug,
data: {
email: devUser.email,
password: devUser.password,
},
depth: 0,
overrideAccess: true,
}),
...[...Array(11)].map(
() => () =>
_payload.create({
collection: postsCollectionSlug,
data: {
title: 'Title',
description: 'Description',
},
depth: 0,
overrideAccess: true,
}),
),
() =>
_payload.create({
collection: customViews1CollectionSlug,
data: {
title: 'Custom View',
},
depth: 0,
overrideAccess: true,
}),
() =>
_payload.create({
collection: customViews2CollectionSlug,
data: {
title: 'Custom View',
},
depth: 0,
overrideAccess: true,
}),
() =>
_payload.create({
collection: geoCollectionSlug,
data: {
point: [7, -7],
},
depth: 0,
overrideAccess: true,
}),
() =>
_payload.create({
collection: geoCollectionSlug,
data: {
point: [5, -5],
},
depth: 0,
overrideAccess: true,
}),
() =>
_payload.create({
collection: noApiViewCollectionSlug,
data: {},
depth: 0,
overrideAccess: true,
}),
() =>
_payload.create({
collection: 'customIdTab',
data: {
id: customIdCollectionId,
title: 'Hello world title',
},
depth: 0,
overrideAccess: true,
}),
() =>
_payload.create({
collection: 'customIdRow',
data: {
id: customIdCollectionId,
title: 'Hello world title',
},
depth: 0,
overrideAccess: true,
}),
],
parallel,
)
},
seedFunction: seed,
})
}