mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-20 07:10:02 +00:00
fix: optimize json content migration (#7252)
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
parent
e4221f779f
commit
9014020ca7
@ -13,7 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
|
|
||||||
import { saveCollabJson, saveCollabYdoc, yDocFromBuffer } from '@hcengineering/collaboration'
|
import { saveCollabJson } from '@hcengineering/collaboration'
|
||||||
import core, {
|
import core, {
|
||||||
coreId,
|
coreId,
|
||||||
DOMAIN_MODEL_TX,
|
DOMAIN_MODEL_TX,
|
||||||
@ -348,10 +348,6 @@ async function processMigrateJsonForDoc (
|
|||||||
? `${attribute.attributeOf}.${attribute.name}`
|
? `${attribute.attributeOf}.${attribute.name}`
|
||||||
: attribute.name
|
: attribute.name
|
||||||
|
|
||||||
// Name of existing ydoc document
|
|
||||||
// original value here looks like '65b7f82f4d422b89d4cbdd6f:HEAD:0'
|
|
||||||
// where the first part is the blob id
|
|
||||||
const currentYdocId = value.split(':')[0] as Ref<Blob>
|
|
||||||
const collabId = makeDocCollabId(doc, attribute.name)
|
const collabId = makeDocCollabId(doc, attribute.name)
|
||||||
|
|
||||||
if (value.startsWith('{')) {
|
if (value.startsWith('{')) {
|
||||||
@ -361,34 +357,34 @@ async function processMigrateJsonForDoc (
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!value.includes(':')) {
|
||||||
|
// not a collaborative document, skip
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name of existing ydoc document
|
||||||
|
// original value here looks like '65b7f82f4d422b89d4cbdd6f:HEAD:0'
|
||||||
|
// where the first part is the blob id
|
||||||
|
const currentYdocId = value.split(':')[0] as Ref<Blob>
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const stat = await storageAdapter.stat(ctx, workspaceId, currentYdocId)
|
// If document id has changed, save it with new name to ensure we will be able to load it later
|
||||||
if (stat !== undefined) {
|
const ydocId = makeCollabYdocId(collabId)
|
||||||
if (stat.contentType.includes('application/ydoc')) {
|
if (ydocId !== currentYdocId) {
|
||||||
const buffer = await storageAdapter.read(ctx, workspaceId, currentYdocId)
|
ctx.info('saving collaborative doc with new name', { collabId, ydocId, currentYdocId })
|
||||||
const ydoc = yDocFromBuffer(Buffer.concat(buffer as any))
|
const buffer = await storageAdapter.read(ctx, workspaceId, currentYdocId)
|
||||||
|
await storageAdapter.put(
|
||||||
// If document id has changed, save it with new name to ensure we will be able to load it later
|
ctx,
|
||||||
const ydocId = makeCollabYdocId(collabId)
|
workspaceId,
|
||||||
if (ydocId !== currentYdocId) {
|
ydocId,
|
||||||
ctx.info('saving collaborative doc with new name', { collabId, ydocId, currentYdocId })
|
Buffer.concat(buffer as any),
|
||||||
await saveCollabYdoc(ctx, storageAdapter, workspaceId, collabId, ydoc)
|
'application/ydoc',
|
||||||
// do not bother with deletion so we can restore content is something goes wrong
|
buffer.length
|
||||||
// await storageAdapter.remove(ctx, client.workspaceId, [currentYdocId])
|
)
|
||||||
}
|
|
||||||
|
|
||||||
// Save document as JSON and save blob Id
|
|
||||||
const jsonId = await saveCollabJson(ctx, storageAdapter, workspaceId, collabId, ydoc)
|
|
||||||
update[attributeName] = jsonId
|
|
||||||
} else {
|
|
||||||
// it is not ydoc, do nothing
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// document is empty, unset
|
|
||||||
const unset = update.$unset ?? {}
|
|
||||||
update.$unset = { ...unset, [attribute.name]: 1 }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const unset = update.$unset ?? {}
|
||||||
|
update.$unset = { ...unset, [attribute.name]: 1 }
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.warn('failed to process collaborative doc', { workspaceId, collabId, currentYdocId, err })
|
ctx.warn('failed to process collaborative doc', { workspaceId, collabId, currentYdocId, err })
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user