group cleanups for YText changes into a single transaction
Fixes #522 but is still massively slow
This commit is contained in:
parent
00ef472d68
commit
3741f43a11
@ -859,12 +859,21 @@ export class YText extends AbstractType {
|
|||||||
_callObserver (transaction, parentSubs) {
|
_callObserver (transaction, parentSubs) {
|
||||||
super._callObserver(transaction, parentSubs)
|
super._callObserver(transaction, parentSubs)
|
||||||
const event = new YTextEvent(this, transaction, parentSubs)
|
const event = new YTextEvent(this, transaction, parentSubs)
|
||||||
const doc = transaction.doc
|
|
||||||
callTypeObservers(this, transaction, event)
|
callTypeObservers(this, transaction, event)
|
||||||
// If a remote change happened, we try to cleanup potential formatting duplicates.
|
// If a remote change happened, we try to cleanup potential formatting duplicates.
|
||||||
|
if (!transaction.local) {
|
||||||
|
transaction._yTexts.push(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Transaction} transaction
|
||||||
|
*/
|
||||||
|
_cleanup (transaction) {
|
||||||
if (!transaction.local) {
|
if (!transaction.local) {
|
||||||
// check if another formatting item was inserted
|
// check if another formatting item was inserted
|
||||||
let foundFormattingItem = false
|
let foundFormattingItem = false
|
||||||
|
const doc = transaction.doc
|
||||||
for (const [client, afterClock] of transaction.afterState.entries()) {
|
for (const [client, afterClock] of transaction.afterState.entries()) {
|
||||||
const clock = transaction.beforeState.get(client) || 0
|
const clock = transaction.beforeState.get(client) || 0
|
||||||
if (afterClock === clock) {
|
if (afterClock === clock) {
|
||||||
|
@ -11,7 +11,7 @@ import {
|
|||||||
Item,
|
Item,
|
||||||
generateNewClientId,
|
generateNewClientId,
|
||||||
createID,
|
createID,
|
||||||
UpdateEncoderV1, UpdateEncoderV2, GC, StructStore, AbstractType, AbstractStruct, YEvent, Doc // eslint-disable-line
|
UpdateEncoderV1, UpdateEncoderV2, GC, StructStore, AbstractType, AbstractStruct, YEvent, Doc, YText // eslint-disable-line
|
||||||
} from '../internals.js'
|
} from '../internals.js'
|
||||||
|
|
||||||
import * as map from 'lib0/map'
|
import * as map from 'lib0/map'
|
||||||
@ -114,6 +114,10 @@ export class Transaction {
|
|||||||
* @type {Set<Doc>}
|
* @type {Set<Doc>}
|
||||||
*/
|
*/
|
||||||
this.subdocsLoaded = new Set()
|
this.subdocsLoaded = new Set()
|
||||||
|
/**
|
||||||
|
* @type {Array<YText>}
|
||||||
|
*/
|
||||||
|
this._yTexts = []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,6 +299,13 @@ const cleanupTransactions = (transactionCleanups, i) => {
|
|||||||
fs.push(() => doc.emit('afterTransaction', [transaction, doc]))
|
fs.push(() => doc.emit('afterTransaction', [transaction, doc]))
|
||||||
})
|
})
|
||||||
callAll(fs, [])
|
callAll(fs, [])
|
||||||
|
if (transaction._yTexts.length > 0) {
|
||||||
|
transact(doc, () => {
|
||||||
|
transaction._yTexts.forEach(yText => {
|
||||||
|
yText._cleanup(transaction)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// Replace deleted items with ItemDeleted / GC.
|
// Replace deleted items with ItemDeleted / GC.
|
||||||
// This is where content is actually remove from the Yjs Doc.
|
// This is where content is actually remove from the Yjs Doc.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user