-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(migrate): limit request concurrency
- Loading branch information
Showing
8 changed files
with
84 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/@sanity/migrate/src/destinations/commitMutations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {pMapIterable} from 'p-map' | ||
import {MultipleMutationResult} from '@sanity/client' | ||
import {fetchAsyncIterator, FetchOptions} from '../fetch-utils/fetchStream' | ||
import {parseJSON} from '../it-utils/json' | ||
import {decodeText} from '../it-utils/decodeText' | ||
import {concatStr} from '../it-utils/concatStr' | ||
import {lastValueFrom} from '../it-utils/lastValueFrom' | ||
|
||
export function commitMutations( | ||
fetchOptions: AsyncIterableIterator<FetchOptions>, | ||
options: {concurrency: number}, | ||
) { | ||
return pMapIterable( | ||
fetchOptions, | ||
async (opts): Promise<MultipleMutationResult> => | ||
lastValueFrom(parseJSON(concatStr(decodeText(await fetchAsyncIterator(opts))))), | ||
{concurrency: options.concurrency}, | ||
) | ||
} |
38 changes: 0 additions & 38 deletions
38
packages/@sanity/migrate/src/destinations/toMutationEndpoint.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
interface Options<T> { | ||
defaultValue?: T | ||
} | ||
export async function lastValueFrom<T>( | ||
it: AsyncIterableIterator<T>, | ||
options?: Options<T>, | ||
): Promise<T> { | ||
const defaultGiven = 'defaultValue' in (options ?? {}) | ||
let latestValue: T | undefined | ||
let didYield = false | ||
|
||
for await (const value of it) { | ||
didYield = true | ||
latestValue = value | ||
} | ||
if (!didYield) { | ||
if (defaultGiven) { | ||
return options!.defaultValue! | ||
} | ||
throw new Error( | ||
'No value yielded from async iterable. If this iterable is empty, provide a default value.', | ||
) | ||
} | ||
return latestValue! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const MUTATION_ENDPOINT_MAX_BODY_SIZE = 1024 * 256 // 256KB | ||
export const DEFAULT_MUTATION_CONCURRENCY = 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters