more updates to convert to automerge
This commit is contained in:
parent
a82f8faa00
commit
663c845cab
|
|
@ -450,6 +450,7 @@ export class AutomergeDurableObject {
|
||||||
if (!this.roomPromise) {
|
if (!this.roomPromise) {
|
||||||
this.roomPromise = (async () => {
|
this.roomPromise = (async () => {
|
||||||
let initialDoc: any
|
let initialDoc: any
|
||||||
|
let wasConverted = false
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// fetch the document from R2
|
// fetch the document from R2
|
||||||
|
|
@ -471,6 +472,7 @@ export class AutomergeDurableObject {
|
||||||
// This is the raw Automerge document format - convert to store format
|
// This is the raw Automerge document format - convert to store format
|
||||||
console.log(`Converting Automerge document format to store format for room ${this.roomId}`)
|
console.log(`Converting Automerge document format to store format for room ${this.roomId}`)
|
||||||
initialDoc = this.convertAutomergeToStore(rawDoc)
|
initialDoc = this.convertAutomergeToStore(rawDoc)
|
||||||
|
wasConverted = true
|
||||||
const customRecords = Object.values(initialDoc.store).filter((r: any) =>
|
const customRecords = Object.values(initialDoc.store).filter((r: any) =>
|
||||||
r.id && typeof r.id === 'string' && r.id.startsWith('obsidian_vault:')
|
r.id && typeof r.id === 'string' && r.id.startsWith('obsidian_vault:')
|
||||||
)
|
)
|
||||||
|
|
@ -496,6 +498,7 @@ export class AutomergeDurableObject {
|
||||||
// Migrate old format (documents array) to new format (store object)
|
// Migrate old format (documents array) to new format (store object)
|
||||||
console.log(`Migrating old documents format to new store format for room ${this.roomId}`)
|
console.log(`Migrating old documents format to new store format for room ${this.roomId}`)
|
||||||
initialDoc = this.migrateDocumentsToStore(rawDoc)
|
initialDoc = this.migrateDocumentsToStore(rawDoc)
|
||||||
|
wasConverted = true
|
||||||
const customRecords = Object.values(initialDoc.store).filter((r: any) =>
|
const customRecords = Object.values(initialDoc.store).filter((r: any) =>
|
||||||
r.id && typeof r.id === 'string' && r.id.startsWith('obsidian_vault:')
|
r.id && typeof r.id === 'string' && r.id.startsWith('obsidian_vault:')
|
||||||
)
|
)
|
||||||
|
|
@ -536,6 +539,24 @@ export class AutomergeDurableObject {
|
||||||
// Initialize the last persisted hash with the loaded document
|
// Initialize the last persisted hash with the loaded document
|
||||||
this.lastPersistedHash = this.generateDocHash(initialDoc)
|
this.lastPersistedHash = this.generateDocHash(initialDoc)
|
||||||
|
|
||||||
|
// If document was converted/migrated, persist it immediately to save in new format
|
||||||
|
if (wasConverted && initialDoc.store && Object.keys(initialDoc.store).length > 0) {
|
||||||
|
console.log(`📦 Persisting converted document to R2 in new format for room ${this.roomId}`)
|
||||||
|
// Persist immediately without throttling for converted documents
|
||||||
|
try {
|
||||||
|
const docJson = JSON.stringify(initialDoc)
|
||||||
|
await this.r2.put(`rooms/${this.roomId}`, docJson, {
|
||||||
|
httpMetadata: {
|
||||||
|
contentType: 'application/json'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.lastPersistedHash = this.generateDocHash(initialDoc)
|
||||||
|
console.log(`✅ Successfully persisted converted document for room ${this.roomId}`)
|
||||||
|
} catch (persistError) {
|
||||||
|
console.error(`❌ Error persisting converted document for room ${this.roomId}:`, persistError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return initialDoc
|
return initialDoc
|
||||||
})()
|
})()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,9 @@ new_classes = ["AutomergeDurableObject"]
|
||||||
|
|
||||||
[[migrations]]
|
[[migrations]]
|
||||||
tag = "v2"
|
tag = "v2"
|
||||||
deleted_classes = ["TldrawDurableObject"]
|
renamed_classes = [
|
||||||
|
{ from = "TldrawDurableObject", to = "AutomergeDurableObject" }
|
||||||
|
]
|
||||||
|
|
||||||
[[r2_buckets]]
|
[[r2_buckets]]
|
||||||
binding = 'TLDRAW_BUCKET'
|
binding = 'TLDRAW_BUCKET'
|
||||||
|
|
@ -67,7 +69,9 @@ new_classes = ["AutomergeDurableObject"]
|
||||||
|
|
||||||
[[env.dev.migrations]]
|
[[env.dev.migrations]]
|
||||||
tag = "v2"
|
tag = "v2"
|
||||||
deleted_classes = ["TldrawDurableObject"]
|
renamed_classes = [
|
||||||
|
{ from = "TldrawDurableObject", to = "AutomergeDurableObject" }
|
||||||
|
]
|
||||||
|
|
||||||
[[env.dev.r2_buckets]]
|
[[env.dev.r2_buckets]]
|
||||||
binding = 'TLDRAW_BUCKET'
|
binding = 'TLDRAW_BUCKET'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue