summaryrefslogtreecommitdiff
path: root/lib/workers
diff options
context:
space:
mode:
authorWu Cheng-Han2016-11-16 13:58:54 +0800
committerWu Cheng-Han2016-11-16 13:58:54 +0800
commit7adb78aba81a2ac9b87d82d7d879b70d315cf8e8 (patch)
treee118d562d65ff6f828e966eb240e35dc428f0e04 /lib/workers
parentc5de552988810766ad56f0ea1550bb1c6d5f5a2a (diff)
Revert "Add workers for history to leverage CPU intensive work loading"
This reverts commit b5920fbbd1ceb595456da18f7d458b63d1a960bf.
Diffstat (limited to 'lib/workers')
-rw-r--r--lib/workers/historyUpdater.js66
1 files changed, 0 insertions, 66 deletions
diff --git a/lib/workers/historyUpdater.js b/lib/workers/historyUpdater.js
deleted file mode 100644
index df80e92d..00000000
--- a/lib/workers/historyUpdater.js
+++ /dev/null
@@ -1,66 +0,0 @@
-// external modules
-var async = require('async');
-
-// core
-var config = require("../config.js");
-var logger = require("../logger.js");
-var models = require("../models");
-
-process.on('message', function (data) {
- if (!data || !data.msg || data.msg !== 'update history' || !data.caches) return process.exit();
- var caches = data.caches;
- async.each(Object.keys(caches), function (key, callback) {
- var cache = caches[key];
- if (config.debug) logger.info("history updater found dirty history: " + key);
- var history = parseHistoryToArray(cache);
- finishUpdateHistory(key, history, function (err, count) {
- if (err) return callback(err, null);
- if (!count) return callback(null, null);
- process.send({
- msg: 'check',
- userid: key
- });
- return callback(null, null);
- });
- }, function (err) {
- if (err) logger.error('history updater error', err);
- process.exit();
- });
-});
-
-function finishUpdateHistory(userid, history, callback) {
- models.User.update({
- history: JSON.stringify(history)
- }, {
- where: {
- id: userid
- }
- }).then(function (count) {
- return callback(null, count);
- }).catch(function (err) {
- return callback(err, null);
- });
-}
-
-function parseHistoryToArray(history) {
- var _history = [];
- Object.keys(history).forEach(function (key) {
- var item = history[key];
- _history.push(item);
- });
- return _history;
-}
-
-function parseHistoryToObject(history) {
- var _history = {};
- for (var i = 0, l = history.length; i < l; i++) {
- var item = history[i];
- _history[item.id] = item;
- }
- return _history;
-}
-
-module.exports = {
- parseHistoryToArray: parseHistoryToArray,
- parseHistoryToObject: parseHistoryToObject
-}; \ No newline at end of file