Skip to content

Commit

Permalink
fixup! feat(migrate): implement mutation batcher and use when submitt…
Browse files Browse the repository at this point in the history
…ing against mutate endpoint
  • Loading branch information
bjoerge committed Jan 24, 2024
1 parent a873556 commit 0cb219a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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* () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 0cb219a

Please sign in to comment.