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:
@@ -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());
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user