mirror of https://github.com/status-im/codimd.git
Update to make doc only update while the filesystem content not equals db content
This commit is contained in:
parent
9c89876263
commit
8d24d9e97f
|
@ -114,11 +114,14 @@ module.exports = function (sequelize, DataTypes) {
|
||||||
// then will update the doc in db
|
// then will update the doc in db
|
||||||
var fsModifiedTime = moment(fs.statSync(filePath).mtime);
|
var fsModifiedTime = moment(fs.statSync(filePath).mtime);
|
||||||
var dbModifiedTime = moment(note.lastchangeAt || note.createdAt);
|
var dbModifiedTime = moment(note.lastchangeAt || note.createdAt);
|
||||||
if (fsModifiedTime.isAfter(dbModifiedTime)) {
|
var body = fs.readFileSync(filePath, 'utf8');
|
||||||
var body = fs.readFileSync(filePath, 'utf8');
|
var title = Note.parseNoteTitle(body);
|
||||||
|
body = LZString.compressToBase64(body);
|
||||||
|
title = LZString.compressToBase64(title);
|
||||||
|
if (fsModifiedTime.isAfter(dbModifiedTime) && note.content !== body) {
|
||||||
note.update({
|
note.update({
|
||||||
title: LZString.compressToBase64(Note.parseNoteTitle(body)),
|
title: title,
|
||||||
content: LZString.compressToBase64(body),
|
content: body,
|
||||||
lastchangeAt: fsModifiedTime
|
lastchangeAt: fsModifiedTime
|
||||||
}).then(function (note) {
|
}).then(function (note) {
|
||||||
sequelize.models.Revision.saveNoteRevision(note, function (err, revision) {
|
sequelize.models.Revision.saveNoteRevision(note, function (err, revision) {
|
||||||
|
|
Loading…
Reference in New Issue