summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWu Cheng-Han2016-08-14 11:22:54 +0800
committerWu Cheng-Han2016-08-14 11:22:54 +0800
commit8d24d9e97fe362f6cfd63da32ec4f4bd07b5bd9a (patch)
tree966de1954da43b289e198b5bbf103b595908cbc1 /lib
parent9c898762636bd9785e039597606be8213851d5a2 (diff)
Update to make doc only update while the filesystem content not equals db content
Diffstat (limited to 'lib')
-rw-r--r--lib/models/note.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/models/note.js b/lib/models/note.js
index 05babb42..3577d401 100644
--- a/lib/models/note.js
+++ b/lib/models/note.js
@@ -114,11 +114,14 @@ module.exports = function (sequelize, DataTypes) {
// then will update the doc in db
var fsModifiedTime = moment(fs.statSync(filePath).mtime);
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({
- title: LZString.compressToBase64(Note.parseNoteTitle(body)),
- content: LZString.compressToBase64(body),
+ title: title,
+ content: body,
lastchangeAt: fsModifiedTime
}).then(function (note) {
sequelize.models.Revision.saveNoteRevision(note, function (err, revision) {