From 0cb219ac8ff9f820bf51ea5dbd905afe5b293570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Wed, 24 Jan 2024 14:24:51 +0100 Subject: [PATCH] fixup! feat(migrate): implement mutation batcher and use when submitting against mutate endpoint --- .../src/runner/utils/__tests__/batchMutations.test.ts | 5 ++--- packages/@sanity/migrate/src/runner/utils/batchMutations.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/@sanity/migrate/src/runner/utils/__tests__/batchMutations.test.ts b/packages/@sanity/migrate/src/runner/utils/__tests__/batchMutations.test.ts index 50d9857b7fe..d25eccb97ad 100644 --- a/packages/@sanity/migrate/src/runner/utils/__tests__/batchMutations.test.ts +++ b/packages/@sanity/migrate/src/runner/utils/__tests__/batchMutations.test.ts @@ -1,5 +1,3 @@ -import {at, createIfNotExists, createOrReplace, patch, set} from '@bjoerge/mutiny' -import {Mutation} from '@sanity/client' import {batchMutations} from '../batchMutations' function byteLength(obj: unknown) { @@ -40,7 +38,8 @@ describe('mutation payload batching', () => { expect(await it.next()).toEqual({value: [second], done: false}) expect(await it.next()).toEqual({value: undefined, done: true}) }) - test('when each mutation is smaller then max batch size', async () => { + + test('when each mutation is bigger than max batch size', async () => { const first = {createIfNotExists: {_id: 'foo', _type: 'something', bar: 'baz'}} const second = {patch: {id: 'foo', set: {bar: 'baz'}}} const gen = async function* () { diff --git a/packages/@sanity/migrate/src/runner/utils/batchMutations.ts b/packages/@sanity/migrate/src/runner/utils/batchMutations.ts index 23e96da77fa..1cc89c408dc 100644 --- a/packages/@sanity/migrate/src/runner/utils/batchMutations.ts +++ b/packages/@sanity/migrate/src/runner/utils/batchMutations.ts @@ -31,7 +31,7 @@ export async function* batchMutations( const mutationSize = JSON.stringify(mutation).length if (mutationSize >= maxBatchSize + PADDING_SIZE) { - // the mutation size itself is bigger then max batch size, yield it as a single batch and hope for the best (the server has a bigger limit) + // the mutation size itself is bigger than max batch size, yield it as a single batch and hope for the best (the server has a bigger limit) if (currentBatch.length) { yield currentBatch }