Update to remove history cache to lower application coupling

This commit is contained in:
Wu Cheng-Han 2017-02-03 21:39:08 +08:00
parent a261c8e812
commit 92ad67b813
3 changed files with 64 additions and 114 deletions

View file

@ -122,6 +122,12 @@ function updateNote(note, callback) {
}
}).then(function (_note) {
if (!_note) return callback(null, null);
// update user note history
var tempUsers = Object.assign({}, note.tempUsers);
note.tempUsers = {};
Object.keys(tempUsers).forEach(function (key) {
updateHistory(key, note, tempUsers[key]);
});
if (note.lastchangeuser) {
if (_note.lastchangeuserId != note.lastchangeuser) {
models.User.findOne({
@ -405,10 +411,7 @@ function finishConnection(socket, note, user) {
note.server.setColor(socket, user.color);
// update user note history
setTimeout(function () {
var noteId = note.alias ? note.alias : LZString.compressToBase64(note.id);
if (note.server) history.updateHistory(user.userid, noteId, note.server.document);
}, 0);
updateHistory(user.userid, note);
emitOnlineUsers(socket);
emitRefresh(socket);
@ -497,6 +500,7 @@ function startConnection(socket) {
lastchangeuserprofile: lastchangeuserprofile,
socks: [],
users: {},
tempUsers: {},
createtime: moment(createtime).valueOf(),
updatetime: moment(updatetime).valueOf(),
server: server,
@ -687,15 +691,14 @@ function operationCallback(socket, operation) {
return logger.error('operation callback failed: ' + err);
});
}
// update user note history
setTimeout(function() {
var noteId = note.alias ? note.alias : LZString.compressToBase64(note.id);
if (note.server) history.updateHistory(userId, noteId, note.server.document);
}, 0);
note.tempUsers[userId] = Date.now();
}
// save authorship
note.authorship = models.Note.updateAuthorshipByOperation(operation, userId, note.authorship);
function updateHistory(userId, note, time) {
var noteId = note.alias ? note.alias : LZString.compressToBase64(note.id);
if (note.server) history.updateHistory(userId, noteId, note.server.document, time);
}
function connection(socket) {
@ -925,4 +928,4 @@ function connection(socket) {
});
}
module.exports = realtime;
module.exports = realtime;