mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-16 13:21:57 +00:00
UBERF-6557: Clean old domains during clone of workspace to new place (#5361)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
cd696ec845
commit
04bb873191
@ -287,6 +287,9 @@ export async function cloneWorkspace (
|
|||||||
console.log('Retrieve chunk:', needRetrieve.length)
|
console.log('Retrieve chunk:', needRetrieve.length)
|
||||||
let docs: Doc[] = []
|
let docs: Doc[] = []
|
||||||
try {
|
try {
|
||||||
|
// We need to clean target connection before copying something.
|
||||||
|
await cleanDomain(targetConnection, c)
|
||||||
|
|
||||||
docs = await sourceConnection.loadDocs(c, needRetrieve)
|
docs = await sourceConnection.loadDocs(c, needRetrieve)
|
||||||
if (clearTime) {
|
if (clearTime) {
|
||||||
docs = docs.map((p) => {
|
docs = docs.map((p) => {
|
||||||
@ -337,6 +340,32 @@ export async function cloneWorkspace (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function cleanDomain (connection: CoreClient & BackupClient, domain: Domain): Promise<void> {
|
||||||
|
// Load all digest from collection.
|
||||||
|
let idx: number | undefined
|
||||||
|
const ids: Ref<Doc>[] = []
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
const it = await connection.loadChunk(domain, idx)
|
||||||
|
idx = it.idx
|
||||||
|
|
||||||
|
ids.push(...it.docs.map((it) => it.id as Ref<Doc>))
|
||||||
|
if (it.finished) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error(err)
|
||||||
|
if (idx !== undefined) {
|
||||||
|
await connection.closeChunk(idx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (ids.length > 0) {
|
||||||
|
const part = ids.splice(0, 5000)
|
||||||
|
await connection.clean(domain, part)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user