summaryrefslogtreecommitdiff
path: root/app.js
diff options
context:
space:
mode:
authorWu Cheng-Han2016-10-10 20:51:46 +0800
committerWu Cheng-Han2016-10-10 20:51:46 +0800
commitaf77bb8f59adade4e99886dfc37f716f074294fb (patch)
tree932a71eae465a20157bb94072598d97b5b1dfbd1 /app.js
parentdc343978eb29da741b7f52137e042996ab78b63a (diff)
Update to add cache to history
Diffstat (limited to 'app.js')
-rw-r--r--app.js56
1 files changed, 5 insertions, 51 deletions
diff --git a/app.js b/app.js
index b3473a13..86df1010 100644
--- a/app.js
+++ b/app.js
@@ -22,6 +22,7 @@ var i18n = require('i18n');
var config = require("./lib/config.js");
var logger = require("./lib/logger.js");
var auth = require("./lib/auth.js");
+var history = require("./lib/history.js");
var response = require("./lib/response.js");
var models = require("./lib/models");
@@ -365,56 +366,9 @@ app.get('/logout', function (req, res) {
res.redirect(config.serverurl + '/');
});
//get history
-app.get('/history', function (req, res) {
- if (req.isAuthenticated()) {
- models.User.findOne({
- where: {
- id: req.user.id
- }
- }).then(function (user) {
- if (!user)
- return response.errorNotFound(res);
- var history = [];
- if (user.history)
- history = JSON.parse(user.history);
- res.send({
- history: history
- });
- if (config.debug)
- logger.info('read history success: ' + user.id);
- }).catch(function (err) {
- logger.error('read history failed: ' + err);
- return response.errorInternalError(res);
- });
- } else {
- return response.errorForbidden(res);
- }
-});
+app.get('/history', history.historyGet);
//post history
-app.post('/history', urlencodedParser, function (req, res) {
- if (req.isAuthenticated()) {
- if (config.debug)
- logger.info('SERVER received history from [' + req.user.id + ']: ' + req.body.history);
- models.User.update({
- history: req.body.history
- }, {
- where: {
- id: req.user.id
- }
- }).then(function (count) {
- if (!count)
- return response.errorNotFound(res);
- if (config.debug)
- logger.info("write user history success: " + req.user.id);
- }).catch(function (err) {
- logger.error('write history failed: ' + err);
- return response.errorInternalError(res);
- });
- res.end();
- } else {
- return response.errorForbidden(res);
- }
-});
+app.post('/history', urlencodedParser, history.historyPost);
//get me info
app.get('/me', function (req, res) {
if (req.isAuthenticated()) {
@@ -522,7 +476,7 @@ function startListen() {
// sync db then start listen
models.sequelize.sync().then(function () {
// check if realtime is ready
- if (realtime.isReady()) {
+ if (history.isReady() && realtime.isReady()) {
models.Revision.checkAllNotesRevision(function (err, notes) {
if (err) return new Error(err);
if (!notes || notes.length <= 0) return startListen();
@@ -549,7 +503,7 @@ process.on('SIGINT', function () {
socket.disconnect(true);
});
var checkCleanTimer = setInterval(function () {
- if (realtime.isReady()) {
+ if (history.isReady() && realtime.isReady()) {
models.Revision.checkAllNotesRevision(function (err, notes) {
if (err) return new Error(err);
if (notes.length <= 0) {