1.18.0 performance items: tests, the reference budget gate tightened (JS 195 kB, 404 without its exception, TTL check), docs (performance.md, AGENT.md, iapl-performance, module pages, api.md), changelog: what changes for an existing site
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d628839235
commit
f0127ac1b8
@@ -91,7 +91,7 @@ describe('TTL indexes (item 10)', () => {
|
||||
return {}
|
||||
},
|
||||
}
|
||||
const payload = { db: { collections: { 'consent-records': { collection: coll } }, connection: { db: { command: async (c: object) => void calls.push(`collMod ${JSON.stringify(c)}`) } }, name: 'mongoose' } }
|
||||
const payload = { db: { name: 'mongoose', collections: { 'consent-records': { collection: coll } }, connection: { db: { command: async (c: object) => void calls.push(`collMod ${JSON.stringify(c)}`) } } } }
|
||||
return { calls, payload: payload as never }
|
||||
}
|
||||
|
||||
@@ -99,18 +99,18 @@ describe('TTL indexes (item 10)', () => {
|
||||
const { calls, payload } = fake([{ name: '_id_' }, { name: 'createdAt_1' }])
|
||||
expect(await syncTtlIndex(payload, 'consent-records', { days: 1095, enabled: true, from: 'createdAt' })).toBe('created')
|
||||
expect(calls).toEqual([
|
||||
`backfill {"${TTL_FIELD}":{"$exists":false},"createdAt":{"$type":"date"}} [{"$set":{"${TTL_FIELD}":"$createdAt"}}]`,
|
||||
`backfill {"createdAt":{"$type":"date"},"${TTL_FIELD}":{"$exists":false}} [{"$set":{"${TTL_FIELD}":"$createdAt"}}]`,
|
||||
`create {"${TTL_FIELD}":1} ${1095 * 86_400}`,
|
||||
])
|
||||
})
|
||||
|
||||
test('a changed retention moves the index (collMod); the same one does nothing; off drops it', async () => {
|
||||
const changed = fake([{ expireAfterSeconds: 90 * 86_400, name: TTL_INDEX }])
|
||||
const changed = fake([{ name: TTL_INDEX, expireAfterSeconds: 90 * 86_400 }])
|
||||
expect(await syncTtlIndex(changed.payload, 'consent-records', { days: 30, enabled: true, from: 'lastAt' })).toBe('updated')
|
||||
expect(changed.calls.at(-1)).toBe(`collMod {"collMod":"consent-records","index":{"expireAfterSeconds":${30 * 86_400},"name":"${TTL_INDEX}"}}`)
|
||||
const same = fake([{ expireAfterSeconds: 30 * 86_400, name: TTL_INDEX }])
|
||||
expect(changed.calls.at(-1)).toBe(`collMod {"collMod":"consent-records","index":{"name":"${TTL_INDEX}","expireAfterSeconds":${30 * 86_400}}}`)
|
||||
const same = fake([{ name: TTL_INDEX, expireAfterSeconds: 30 * 86_400 }])
|
||||
expect(await syncTtlIndex(same.payload, 'consent-records', { days: 30, enabled: true, from: 'lastAt' })).toBe('none')
|
||||
const off = fake([{ expireAfterSeconds: 30 * 86_400, name: TTL_INDEX }])
|
||||
const off = fake([{ name: TTL_INDEX, expireAfterSeconds: 30 * 86_400 }])
|
||||
expect(await syncTtlIndex(off.payload, 'consent-records', { days: 30, enabled: false, from: 'lastAt' })).toBe('dropped')
|
||||
expect(off.calls).toEqual([`drop ${TTL_INDEX}`])
|
||||
})
|
||||
@@ -127,7 +127,7 @@ describe('versions (item 13)', () => {
|
||||
expect(withVersionLimit({ slug: 'site-integrations', versions: true }, 'global').versions).toEqual({ max: 20 })
|
||||
expect(withVersionLimit({ slug: 'forms', versions: { drafts: true } }, 'collection').versions).toEqual({ drafts: true, maxPerDoc: 20 })
|
||||
expect(withVersionLimit({ slug: 'forms', versions: { maxPerDoc: 0 } }, 'collection').versions).toEqual({ maxPerDoc: 0 }) // the project's own (unlimited) wins
|
||||
expect(withVersionLimit({ slug: 'forms' }, 'collection').versions).toBeUndefined()
|
||||
expect(withVersionLimit({ slug: 'forms' } as { slug: string; versions?: unknown }, 'collection').versions).toBeUndefined()
|
||||
})
|
||||
|
||||
test('doctor hint for a project that turns versions on without a limit', async () => {
|
||||
@@ -160,10 +160,10 @@ describe('unused media in the panel (item 12)', () => {
|
||||
find: async ({ collection }: { collection: string }) => ({ docs: docs[collection] ?? [] }),
|
||||
findGlobal: async () => ({}),
|
||||
})
|
||||
const editor = { collection: 'users', id: 1, roles: ['editor'] }
|
||||
const editor = { id: 1, collection: 'users', roles: ['editor'] }
|
||||
|
||||
test('a link to Payload\'s own list filtered to the unused files — nothing is deleted', async () => {
|
||||
const p = payload({ media: [{ filename: 'a.jpg', id: 'm1' }, { filename: 'plan.pdf', id: 'm2' }, { filename: 'b.jpg', id: 'm3' }], pages: [{ hero: 'm1', text: 'see /api/media/file/plan.pdf' }] })
|
||||
const p = payload({ media: [{ id: 'm1', filename: 'a.jpg' }, { id: 'm2', filename: 'plan.pdf' }, { id: 'm3', filename: 'b.jpg' }], pages: [{ hero: 'm1', text: 'see /api/media/file/plan.pdf' }] })
|
||||
const html = renderToStaticMarkup(await UnusedMediaNotice({ adminRoute: '/admin', collection: 'media', i18n: { language: 'en' }, payload: p as never, user: editor }))
|
||||
expect(html).toContain('1 file is not used on any page, entry or setting.')
|
||||
expect(html).toContain('href="/admin/collections/media?where[id][in][0]=m3"')
|
||||
@@ -171,10 +171,10 @@ describe('unused media in the panel (item 12)', () => {
|
||||
})
|
||||
|
||||
test('nothing for a visitor account or when every file is used; only a hint when the site is too big to check here', async () => {
|
||||
const used = payload({ media: [{ filename: 'a.jpg', id: 'm1' }], pages: [{ hero: 'm1' }] })
|
||||
const used = payload({ media: [{ id: 'm1', filename: 'a.jpg' }], pages: [{ hero: 'm1' }] })
|
||||
expect(await UnusedMediaNotice({ collection: 'media', payload: used as never, user: editor })).toBeNull()
|
||||
expect(await UnusedMediaNotice({ collection: 'media', payload: used as never, user: null })).toBeNull()
|
||||
const broken = { ...used, find: async ({ collection }: { collection: string }) => { if (collection === 'pages') {throw new Error('no')} return { docs: [{ filename: 'a.jpg', id: 'm1' }] } } }
|
||||
const broken = { ...used, find: async ({ collection }: { collection: string }) => { if (collection === 'pages') {throw new Error('no')} return { docs: [{ id: 'm1', filename: 'a.jpg' }] } } }
|
||||
expect(renderToStaticMarkup(await UnusedMediaNotice({ collection: 'media', payload: broken as never, user: editor }))).toContain('too many documents to check')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user