Store snapshot on revision

This commit is contained in:
Tom Moor committed 2021-10-25 22:46:20 -07:00
1 parent 043a7b41b5
commit 4d5eed4860
4 files changed
+39 -8

No files matched your search

@@ -0,0 +1,13 @@
"use strict";
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.addColumn("revisions", "state", {
type: Sequelize.BLOB,
});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.removeColumn("revisions", "state");
},
};
+11
View File
@@ -1,5 +1,6 @@
// @flow
import MarkdownSerializer from "slate-md-serializer";
import * as Y from "yjs";
import { DataTypes, sequelize } from "../sequelize";
const serializer = new MarkdownSerializer();
@@ -12,6 +13,7 @@ const Revision = sequelize.define("revision", {
},
version: DataTypes.SMALLINT,
editorVersion: DataTypes.STRING,
state: DataTypes.BLOB,
title: DataTypes.STRING,
text: DataTypes.TEXT,
});
@@ -45,8 +47,17 @@ Revision.findLatest = function (documentId) {
};
Revision.createFromDocument = function (document, options) {
let snapshot;
if (document.state) {
const ydoc = new Y.Doc();
Y.applyUpdate(ydoc, document.state);
snapshot = Buffer.from(Y.encodeSnapshot(Y.snapshot(ydoc)));
}
return Revision.create(
{
state: snapshot,
title: document.title,
text: document.text,
userId: document.lastModifiedById,
+4 -1
View File
@@ -3,6 +3,9 @@ import { Document } from "../../models";
import { globalEventQueue } from "../../queues";
import type { Event } from "../../types";
const delay =
process.env.NODE_ENV === "development" ? 1 * 60 * 1000 : 5 * 60 * 1000;
export default class DebounceProcessor {
async on(event: Event) {
switch (event.name) {
@@ -13,7 +16,7 @@ export default class DebounceProcessor {
name: "documents.update.delayed",
},
{
delay: 5 * 60 * 1000,
delay,
}
);
break;
+11 -7
View File
@@ -8,7 +8,18 @@
"Development": "Development",
"Open document": "Open document",
"New document": "New document",
"Star": "Star",
"Unstar": "Unstar",
"Download": "Download",
"Download document": "Download document",
"Duplicate": "Duplicate",
"Duplicate document": "Duplicate document",
"Document duplicated": "Document duplicated",
"Print": "Print",
"Print document": "Print document",
"Import document": "Import document",
"Templatize": "Templatize",
"Create template": "Create template",
"Home": "Home",
"Search": "Search",
"Drafts": "Drafts",
@@ -198,8 +209,6 @@
"Export": "Export",
"Integrations": "Integrations",
"Installation": "Installation",
"Unstar": "Unstar",
"Star": "Star",
"Previous page": "Previous page",
"Next page": "Next page",
"Could not import file": "Could not import file",
@@ -218,7 +227,6 @@
"Sort in sidebar": "Sort in sidebar",
"Alphabetical sort": "Alphabetical sort",
"Manual sort": "Manual sort",
"Document duplicated": "Document duplicated",
"Document restored": "Document restored",
"Document unpublished": "Document unpublished",
"Document options": "Document options",
@@ -227,15 +235,11 @@
"Unpin": "Unpin",
"Pin to collection": "Pin to collection",
"New nested document": "New nested document",
"Create template": "Create template",
"Duplicate": "Duplicate",
"Unpublish": "Unpublish",
"Permanently delete": "Permanently delete",
"Move": "Move",
"Enable embeds": "Enable embeds",
"Disable embeds": "Disable embeds",
"Download": "Download",
"Print": "Print",
"Move {{ documentName }}": "Move {{ documentName }}",
"Permanently delete {{ documentName }}": "Permanently delete {{ documentName }}",
"Export options": "Export options",