Add optional size parameter to move method for (#7442)

This commit is contained in:
Denis Bykhov 2024-12-12 18:46:42 +05:00 committed by GitHub
parent 294aceffc1
commit 4e7d201560
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 4 deletions

View File

@ -99,7 +99,12 @@ export interface MigrationClient {
) => Promise<void>
// Move documents per domain
move: <T extends Doc>(sourceDomain: Domain, query: DocumentQuery<T>, targetDomain: Domain) => Promise<void>
move: <T extends Doc>(
sourceDomain: Domain,
query: DocumentQuery<T>,
targetDomain: Domain,
size?: number
) => Promise<void>
create: <T extends Doc>(domain: Domain, doc: T | T[]) => Promise<void>
delete: <T extends Doc>(domain: Domain, _id: Ref<T>) => Promise<void>

View File

@ -70,11 +70,16 @@ export class MigrateClientImpl implements MigrationClient {
}
}
async move<T extends Doc>(sourceDomain: Domain, query: DocumentQuery<T>, targetDomain: Domain): Promise<void> {
async move<T extends Doc>(
sourceDomain: Domain,
query: DocumentQuery<T>,
targetDomain: Domain,
size = 500
): Promise<void> {
const ctx = new MeasureMetricsContext('move', {})
this.logger.log('move', { sourceDomain, query })
while (true) {
const source = await this.lowLevel.rawFindAll(sourceDomain, query, { limit: 500 })
const source = await this.lowLevel.rawFindAll(sourceDomain, query, { limit: size })
if (source.length === 0) break
await this.lowLevel.upload(ctx, targetDomain, source)
await this.lowLevel.clean(

View File

@ -332,7 +332,7 @@ export const githubOperationPreTime: MigrateOperation = {
{
state: 'migrate-github-sync-domain',
func: async (client) => {
await client.move(DOMAIN_GITHUB, { _class: github.class.DocSyncInfo }, DOMAIN_GITHUB_SYNC)
await client.move(DOMAIN_GITHUB, { _class: github.class.DocSyncInfo }, DOMAIN_GITHUB_SYNC, 100)
await client.move(DOMAIN_GITHUB, { _class: github.class.GithubUserInfo }, DOMAIN_GITHUB_USER)
}
}