mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-17 08:34:54 -04:00
Remove LZString compression for data storage
This commit is contained in:
parent
c904083d1f
commit
f6d8e3ab00
5 changed files with 28 additions and 37 deletions
|
@ -124,8 +124,6 @@ module.exports = function (sequelize, DataTypes) {
|
|||
var body = fs.readFileSync(filePath, 'utf8');
|
||||
var contentLength = body.length;
|
||||
var title = Note.parseNoteTitle(body);
|
||||
body = LZString.compressToBase64(body);
|
||||
title = LZString.compressToBase64(title);
|
||||
if (fsModifiedTime.isAfter(dbModifiedTime) && note.content !== body) {
|
||||
note.update({
|
||||
title: title,
|
||||
|
@ -135,14 +133,14 @@ module.exports = function (sequelize, DataTypes) {
|
|||
sequelize.models.Revision.saveNoteRevision(note, function (err, revision) {
|
||||
if (err) return _callback(err, null);
|
||||
// update authorship on after making revision of docs
|
||||
var patch = dmp.patch_fromText(LZString.decompressFromBase64(revision.patch));
|
||||
var patch = dmp.patch_fromText(revision.patch);
|
||||
var operations = Note.transformPatchToOperations(patch, contentLength);
|
||||
var authorship = note.authorship ? JSON.parse(LZString.decompressFromBase64(note.authorship)) : [];
|
||||
var authorship = note.authorship;
|
||||
for (var i = 0; i < operations.length; i++) {
|
||||
authorship = Note.updateAuthorshipByOperation(operations[i], null, authorship);
|
||||
}
|
||||
note.update({
|
||||
authorship: LZString.compressToBase64(JSON.stringify(authorship))
|
||||
authorship: JSON.stringify(authorship)
|
||||
}).then(function (note) {
|
||||
return callback(null, note.id);
|
||||
}).catch(function (err) {
|
||||
|
@ -264,10 +262,7 @@ module.exports = function (sequelize, DataTypes) {
|
|||
return markdown.substr(0, 100).replace(/(?:\r\n|\r|\n)/g, ' ');
|
||||
},
|
||||
decodeTitle: function (title) {
|
||||
var decodedTitle = LZString.decompressFromBase64(title);
|
||||
if (decodedTitle) title = decodedTitle;
|
||||
else title = 'Untitled';
|
||||
return title;
|
||||
return title ? title : 'Untitled';
|
||||
},
|
||||
generateWebTitle: function (title) {
|
||||
title = !title || title == "Untitled" ? "HackMD - Collaborative markdown notes" : title + " - HackMD";
|
||||
|
@ -496,8 +491,8 @@ module.exports = function (sequelize, DataTypes) {
|
|||
if (Note.checkFileExist(filePath)) {
|
||||
var fsCreatedTime = moment(fs.statSync(filePath).ctime);
|
||||
body = fs.readFileSync(filePath, 'utf8');
|
||||
note.title = LZString.compressToBase64(Note.parseNoteTitle(body));
|
||||
note.content = LZString.compressToBase64(body);
|
||||
note.title = Note.parseNoteTitle(body);
|
||||
note.content = body;
|
||||
if (filePath !== config.defaultnotepath) {
|
||||
note.createdAt = fsCreatedTime;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
// external modules
|
||||
var Sequelize = require("sequelize");
|
||||
var LZString = require('lz-string');
|
||||
var async = require('async');
|
||||
var moment = require('moment');
|
||||
var childProcess = require('child_process');
|
||||
|
@ -214,7 +213,7 @@ module.exports = function (sequelize, DataTypes) {
|
|||
Revision.create({
|
||||
noteId: note.id,
|
||||
lastContent: note.content,
|
||||
length: LZString.decompressFromBase64(note.content).length,
|
||||
length: note.content.length,
|
||||
authorship: note.authorship
|
||||
}).then(function (revision) {
|
||||
Revision.finishSaveNoteRevision(note, revision, callback);
|
||||
|
@ -223,8 +222,8 @@ module.exports = function (sequelize, DataTypes) {
|
|||
});
|
||||
} else {
|
||||
var latestRevision = revisions[0];
|
||||
var lastContent = LZString.decompressFromBase64(latestRevision.content || latestRevision.lastContent);
|
||||
var content = LZString.decompressFromBase64(note.content);
|
||||
var lastContent = latestRevision.content || latestRevision.lastContent;
|
||||
var content = note.content;
|
||||
sendDmpWorker({
|
||||
msg: 'create patch',
|
||||
lastDoc: lastContent,
|
||||
|
@ -244,9 +243,9 @@ module.exports = function (sequelize, DataTypes) {
|
|||
} else {
|
||||
Revision.create({
|
||||
noteId: note.id,
|
||||
patch: LZString.compressToBase64(patch),
|
||||
patch: patch,
|
||||
content: note.content,
|
||||
length: LZString.decompressFromBase64(note.content).length,
|
||||
length: note.content.length,
|
||||
authorship: note.authorship
|
||||
}).then(function (revision) {
|
||||
// clear last revision content to reduce db size
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue