mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-10 03:37:43 +02:00
UBERF-7520: Use Bulk for index query updates (#6012)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
+50
-31
@@ -41,40 +41,44 @@ export class BackupClientSession extends ClientSession implements BackupSession
|
||||
async loadChunk (_ctx: ClientSessionCtx, domain: Domain, idx?: number, recheck?: boolean): Promise<void> {
|
||||
this.lastRequest = Date.now()
|
||||
await _ctx.ctx.with('load-chunk', { domain }, async (ctx) => {
|
||||
idx = idx ?? this.idIndex++
|
||||
let chunk: ChunkInfo | undefined = this.chunkInfo.get(idx)
|
||||
if (chunk !== undefined) {
|
||||
chunk.index++
|
||||
if (chunk.finished === undefined) {
|
||||
return {
|
||||
idx,
|
||||
docs: [],
|
||||
finished: true
|
||||
try {
|
||||
idx = idx ?? this.idIndex++
|
||||
let chunk: ChunkInfo | undefined = this.chunkInfo.get(idx)
|
||||
if (chunk !== undefined) {
|
||||
chunk.index++
|
||||
if (chunk.finished === undefined) {
|
||||
return {
|
||||
idx,
|
||||
docs: [],
|
||||
finished: true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
chunk = { idx, iterator: this._pipeline.storage.find(ctx, domain, recheck), finished: false, index: 0 }
|
||||
this.chunkInfo.set(idx, chunk)
|
||||
}
|
||||
} else {
|
||||
chunk = { idx, iterator: this._pipeline.storage.find(ctx, domain, recheck), finished: false, index: 0 }
|
||||
this.chunkInfo.set(idx, chunk)
|
||||
}
|
||||
let size = 0
|
||||
const docs: DocInfo[] = []
|
||||
let size = 0
|
||||
const docs: DocInfo[] = []
|
||||
|
||||
while (size < chunkSize) {
|
||||
const doc = await chunk.iterator.next(ctx)
|
||||
if (doc === undefined) {
|
||||
chunk.finished = true
|
||||
break
|
||||
while (size < chunkSize) {
|
||||
const doc = await chunk.iterator.next(ctx)
|
||||
if (doc === undefined) {
|
||||
chunk.finished = true
|
||||
break
|
||||
}
|
||||
|
||||
size += estimateDocSize(doc)
|
||||
docs.push(doc)
|
||||
}
|
||||
|
||||
size += estimateDocSize(doc)
|
||||
docs.push(doc)
|
||||
await _ctx.sendResponse({
|
||||
idx,
|
||||
docs,
|
||||
finished: chunk.finished
|
||||
})
|
||||
} catch (err: any) {
|
||||
await _ctx.sendResponse({ error: err.message })
|
||||
}
|
||||
|
||||
await _ctx.sendResponse({
|
||||
idx,
|
||||
docs,
|
||||
finished: chunk.finished
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -92,18 +96,33 @@ export class BackupClientSession extends ClientSession implements BackupSession
|
||||
|
||||
async loadDocs (ctx: ClientSessionCtx, domain: Domain, docs: Ref<Doc>[]): Promise<void> {
|
||||
this.lastRequest = Date.now()
|
||||
await ctx.sendResponse(await this._pipeline.storage.load(ctx.ctx, domain, docs))
|
||||
try {
|
||||
const result = await this._pipeline.storage.load(ctx.ctx, domain, docs)
|
||||
await ctx.sendResponse(result)
|
||||
} catch (err: any) {
|
||||
await ctx.sendResponse({ error: err.message })
|
||||
}
|
||||
}
|
||||
|
||||
async upload (ctx: ClientSessionCtx, domain: Domain, docs: Doc[]): Promise<void> {
|
||||
this.lastRequest = Date.now()
|
||||
await this._pipeline.storage.upload(ctx.ctx, domain, docs)
|
||||
try {
|
||||
await this._pipeline.storage.upload(ctx.ctx, domain, docs)
|
||||
} catch (err: any) {
|
||||
await ctx.sendResponse({ error: err.message })
|
||||
return
|
||||
}
|
||||
await ctx.sendResponse({})
|
||||
}
|
||||
|
||||
async clean (ctx: ClientSessionCtx, domain: Domain, docs: Ref<Doc>[]): Promise<void> {
|
||||
this.lastRequest = Date.now()
|
||||
await this._pipeline.storage.clean(ctx.ctx, domain, docs)
|
||||
try {
|
||||
await this._pipeline.storage.clean(ctx.ctx, domain, docs)
|
||||
} catch (err: any) {
|
||||
await ctx.sendResponse({ error: err.message })
|
||||
return
|
||||
}
|
||||
await ctx.sendResponse({})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user