fix: Multiplayer changes attributed to incorrect user (#4282)

* fix: Multiplayer changes attributed to the wrong user, performance improvements

* fix: Actually use _last_ editor
This commit is contained in:
Tom Moor
2022-10-12 09:19:07 -04:00
committed by GitHub
parent 484e912947
commit 7199088d1b
6 changed files with 47 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ import { Node } from "prosemirror-model";
import * as Y from "yjs";
import { sequelize } from "@server/database/sequelize";
import { schema, serializer } from "@server/editor";
import Logger from "@server/logging/Logger";
import { Document, Event } from "@server/models";
export default async function documentCollaborativeUpdater({
@@ -18,7 +19,10 @@ export default async function documentCollaborativeUpdater({
return sequelize.transaction(async (transaction) => {
const document = await Document.unscoped()
.scope("withState")
.findByPk(documentId, {
.findOne({
where: {
id: documentId,
},
transaction,
lock: {
of: Document,
@@ -38,6 +42,11 @@ export default async function documentCollaborativeUpdater({
return;
}
Logger.info(
"multiplayer",
`Persisting ${documentId}, attributed to ${userId}`
);
// extract collaborators from doc user data
const pud = new Y.PermanentUserData(ydoc);
const pudIds = Array.from(pud.clients.values());

View File

@@ -112,7 +112,7 @@ export default async function documentUpdater({
}
if (document.title !== previousTitle) {
Event.schedule({
await Event.schedule({
name: "documents.title_change",
documentId: document.id,
collectionId: document.collectionId,