Try to fix when server have heavy loading cache might not update to db properly

This commit is contained in:
Wu Cheng-Han 2016-12-18 22:52:30 +08:00
parent be3aa3bfd5
commit 62eccd48e5
2 changed files with 2 additions and 2 deletions

View file

@ -27,10 +27,10 @@ var updater = setInterval(function () {
if (cache.isDirty) { if (cache.isDirty) {
if (config.debug) logger.info("history updater found dirty history: " + key); if (config.debug) logger.info("history updater found dirty history: " + key);
var history = parseHistoryToArray(cache.history); var history = parseHistoryToArray(cache.history);
cache.isDirty = false;
finishUpdateHistory(key, history, function (err, count) { finishUpdateHistory(key, history, function (err, count) {
if (err) return callback(err, null); if (err) return callback(err, null);
if (!count) return callback(null, null); if (!count) return callback(null, null);
cache.isDirty = false;
cache.updateAt = Date.now(); cache.updateAt = Date.now();
return callback(null, null); return callback(null, null);
}); });

View file

@ -84,6 +84,7 @@ var updater = setInterval(function () {
var note = notes[key]; var note = notes[key];
if (note.server.isDirty) { if (note.server.isDirty) {
if (config.debug) logger.info("updater found dirty note: " + key); if (config.debug) logger.info("updater found dirty note: " + key);
note.server.isDirty = false;
updateNote(note, function(err, _note) { updateNote(note, function(err, _note) {
// handle when note already been clean up // handle when note already been clean up
if (!notes[key] || !notes[key].server) return callback(null, null); if (!notes[key] || !notes[key].server) return callback(null, null);
@ -104,7 +105,6 @@ var updater = setInterval(function () {
} }
return callback(err, null); return callback(err, null);
} }
note.server.isDirty = false;
note.updatetime = moment(_note.lastchangeAt).valueOf(); note.updatetime = moment(_note.lastchangeAt).valueOf();
emitCheck(note); emitCheck(note);
return callback(null, null); return callback(null, null);