Compare commits

...

1 Commits

Author SHA1 Message Date
Sasha
240940db12 blocks benchmark 2025-01-16 23:38:01 +02:00
4 changed files with 2239 additions and 14 deletions

View File

@@ -1,3 +1,5 @@
import type { Block, BlocksField } from 'payload'
import { lexicalEditor } from '@payloadcms/richtext-lexical'
import { fileURLToPath } from 'node:url'
import path from 'path'
@@ -7,13 +9,19 @@ import { devUser } from '../credentials.js'
import { MediaCollection } from './collections/Media/index.js'
import { PostsCollection, postsSlug } from './collections/Posts/index.js'
import { MenuGlobal } from './globals/Menu/index.js'
import { testBlocks } from './testBlocks.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
const blocks: BlocksField = {
blocks: testBlocks,
type: 'blocks',
name: 'blocks',
}
export default buildConfigWithDefaults({
// ...extend config here
collections: [PostsCollection, MediaCollection],
collections: [PostsCollection, MediaCollection, { slug: 'blocks-collection', fields: [blocks] }],
admin: {
importMap: {
baseDir: path.resolve(dirname),
@@ -23,6 +31,10 @@ export default buildConfigWithDefaults({
globals: [
// ...add more globals here
MenuGlobal,
{
slug: 'blocks-global',
fields: [blocks],
},
],
onInit: async (payload) => {
await payload.create({

View File

@@ -74,4 +74,53 @@ describe('_Community Tests', () => {
expect(data.doc.title).toEqual('REST API EXAMPLE')
})
it('blocks benchmark', async () => {
for (let i = 0; i < 100; i++) {
await payload.create({
collection: 'blocks-collection',
data: {
blocks: Array.from({ length: 100 }, () => ({
blockType:
Math.random() > 0.5
? 'test-block-2'
: Math.random() > 0.5
? 'test-block-1'
: 'test-block-3',
title: 'asd',
})),
},
})
}
let collection = 0
let global = 0
for (let i = 0; i < 100; i++) {
await payload.updateGlobal({
slug: 'blocks-global',
data: {
blocks: Array.from({ length: 100 }, () => ({
blockType:
Math.random() > 0.5
? 'test-block-2'
: Math.random() > 0.5
? 'test-block-1'
: 'test-block-3',
title: 'asd',
})),
},
})
let now = Date.now()
await payload.find({ collection: 'blocks-collection', limit: 1 })
collection += Date.now() - now
now = Date.now()
await payload.findGlobal({ slug: 'blocks-global' })
global += Date.now() - now
}
payload.logger.info(`COLLECTION - ${collection}MS`)
payload.logger.info(`GLOBAL - ${global}MS`)
})
})

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,907 @@
import type { Block } from 'payload'
export const testBlock1: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
],
slug: 'test-block-1',
}
export const testBlock2: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
],
slug: 'test-block-2',
}
export const testBlock3: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
],
slug: 'test-block-3',
}
export const testBlock4: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
],
slug: 'test-block-4',
}
export const testBlock5: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
],
slug: 'test-block-5',
}
export const testBlock6: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
],
slug: 'test-block-6',
}
export const testBlock7: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
],
slug: 'test-block-7',
}
export const testBlock8: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
],
slug: 'test-block-8',
}
export const testBlock9: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
],
slug: 'test-block-9',
}
export const testBlock10: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
],
slug: 'test-block-10',
}
export const hotspotsBlock1: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'hotspots',
fields: [
{
name: 'hotspot',
fields: [
{
name: 'nr',
required: true,
type: 'text',
},
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'text',
required: true,
type: 'textarea',
},
{
name: 'coordinates',
fields: [
{
name: 'x',
admin: {
description: 'The X coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
{
name: 'y',
admin: {
description: 'The Y coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
],
type: 'group',
},
],
interfaceName: 'Hotspot',
type: 'group',
},
],
type: 'array',
},
],
slug: 'hotspots1',
}
export const hotspotsBlock2: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'hotspots',
fields: [
{
name: 'hotspot',
fields: [
{
name: 'nr',
required: true,
type: 'text',
},
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'text',
required: true,
type: 'textarea',
},
{
name: 'coordinates',
fields: [
{
name: 'x',
admin: {
description: 'The X coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
{
name: 'y',
admin: {
description: 'The Y coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
],
type: 'group',
},
],
interfaceName: 'Hotspot',
type: 'group',
},
],
type: 'array',
},
],
slug: 'hotspots2',
}
export const hotspotsBlock3: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'hotspots',
fields: [
{
name: 'hotspot',
fields: [
{
name: 'nr',
required: true,
type: 'text',
},
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'text',
required: true,
type: 'textarea',
},
{
name: 'coordinates',
fields: [
{
name: 'x',
admin: {
description: 'The X coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
{
name: 'y',
admin: {
description: 'The Y coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
],
type: 'group',
},
],
interfaceName: 'Hotspot',
type: 'group',
},
],
type: 'array',
},
],
slug: 'hotspots3',
}
export const hotspotsBlock4: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'hotspots',
fields: [
{
name: 'hotspot',
fields: [
{
name: 'nr',
required: true,
type: 'text',
},
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'text',
required: true,
type: 'textarea',
},
{
name: 'coordinates',
fields: [
{
name: 'x',
admin: {
description: 'The X coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
{
name: 'y',
admin: {
description: 'The Y coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
],
type: 'group',
},
],
interfaceName: 'Hotspot',
type: 'group',
},
],
type: 'array',
},
],
slug: 'hotspots4',
}
export const hotspotsBlock5: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'hotspots',
fields: [
{
name: 'hotspot',
fields: [
{
name: 'nr',
required: true,
type: 'text',
},
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'text',
required: true,
type: 'textarea',
},
{
name: 'coordinates',
fields: [
{
name: 'x',
admin: {
description: 'The X coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
{
name: 'y',
admin: {
description: 'The Y coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
],
type: 'group',
},
],
interfaceName: 'Hotspot',
type: 'group',
},
],
type: 'array',
},
],
slug: 'hotspots5',
}
export const hotspotsBlock6: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'hotspots',
fields: [
{
name: 'hotspot',
fields: [
{
name: 'nr',
required: true,
type: 'text',
},
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'text',
required: true,
type: 'textarea',
},
{
name: 'coordinates',
fields: [
{
name: 'x',
admin: {
description: 'The X coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
{
name: 'y',
admin: {
description: 'The Y coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
],
type: 'group',
},
],
interfaceName: 'Hotspot',
type: 'group',
},
],
type: 'array',
},
],
slug: 'hotspots6',
}
export const hotspotsBlock7: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'hotspots',
fields: [
{
name: 'hotspot',
fields: [
{
name: 'nr',
required: true,
type: 'text',
},
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'text',
required: true,
type: 'textarea',
},
{
name: 'coordinates',
fields: [
{
name: 'x',
admin: {
description: 'The X coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
{
name: 'y',
admin: {
description: 'The Y coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
],
type: 'group',
},
],
interfaceName: 'Hotspot',
type: 'group',
},
],
type: 'array',
},
],
slug: 'hotspots7',
}
export const hotspotsBlock8: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'hotspots',
fields: [
{
name: 'hotspot',
fields: [
{
name: 'nr',
required: true,
type: 'text',
},
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'text',
required: true,
type: 'textarea',
},
{
name: 'coordinates',
fields: [
{
name: 'x',
admin: {
description: 'The X coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
{
name: 'y',
admin: {
description: 'The Y coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
],
type: 'group',
},
],
interfaceName: 'Hotspot',
type: 'group',
},
],
type: 'array',
},
],
slug: 'hotspots8',
}
export const hotspotsBlock9: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'hotspots',
fields: [
{
name: 'hotspot',
fields: [
{
name: 'nr',
required: true,
type: 'text',
},
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'text',
required: true,
type: 'textarea',
},
{
name: 'coordinates',
fields: [
{
name: 'x',
admin: {
description: 'The X coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
{
name: 'y',
admin: {
description: 'The Y coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
],
type: 'group',
},
],
interfaceName: 'Hotspot',
type: 'group',
},
],
type: 'array',
},
],
slug: 'hotspots9',
}
export const hotspotsBlock10: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'hotspots',
fields: [
{
name: 'hotspot',
fields: [
{
name: 'nr',
required: true,
type: 'text',
},
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'text',
required: true,
type: 'textarea',
},
{
name: 'coordinates',
fields: [
{
name: 'x',
admin: {
description: 'The X coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
{
name: 'y',
admin: {
description: 'The Y coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
],
type: 'group',
},
],
interfaceName: 'Hotspot',
type: 'group',
},
],
type: 'array',
},
],
slug: 'hotspots10',
}
export const hotspotsBlock11: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'hotspots',
fields: [
{
name: 'hotspot',
fields: [
{
name: 'nr',
required: true,
type: 'text',
},
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'text',
required: true,
type: 'textarea',
},
{
name: 'coordinates',
fields: [
{
name: 'x',
admin: {
description: 'The X coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
{
name: 'y',
admin: {
description: 'The Y coordinate of the hotspot in %',
},
max: 100,
min: 0,
required: true,
type: 'number',
},
],
type: 'group',
},
],
interfaceName: 'Hotspot',
type: 'group',
},
],
type: 'array',
},
],
slug: 'hotspots11',
}
const blocksBlock1: Block = {
fields: [
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'blocks',
fields: [
{
name: 'block',
fields: [
{
name: 'title',
required: true,
type: 'text',
},
{
name: 'text',
required: true,
type: 'textarea',
},
{
name: 'blocks',
type: 'blocks',
blocks: [
testBlock1,
testBlock2,
testBlock3,
testBlock4,
testBlock5,
testBlock6,
testBlock7,
testBlock8,
testBlock9,
testBlock10,
hotspotsBlock1,
hotspotsBlock2,
hotspotsBlock3,
hotspotsBlock4,
hotspotsBlock5,
hotspotsBlock6,
],
},
],
interfaceName: 'Block',
type: 'group',
},
],
type: 'array',
},
],
slug: 'blocks1',
}
export const testBlocks = [
testBlock1,
testBlock2,
testBlock3,
testBlock4,
testBlock5,
testBlock6,
testBlock7,
testBlock8,
testBlock9,
testBlock10,
hotspotsBlock1,
hotspotsBlock2,
hotspotsBlock3,
hotspotsBlock4,
hotspotsBlock5,
hotspotsBlock6,
hotspotsBlock7,
hotspotsBlock8,
hotspotsBlock9,
hotspotsBlock10,
hotspotsBlock11,
blocksBlock1,
]