From b4b442c897292218c0142e9cbb2b8d0be0b519ea Mon Sep 17 00:00:00 2001 From: calzoneman Date: Fri, 9 Oct 2015 23:16:21 -0700 Subject: [PATCH] bgtask: run channel saves serially to prevent thrashing --- package.json | 2 +- src/bgtask.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 55d9f820..454beddc 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.11.1", + "version": "3.11.2", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/src/bgtask.js b/src/bgtask.js index a966f60d..e2fb9e75 100644 --- a/src/bgtask.js +++ b/src/bgtask.js @@ -8,6 +8,7 @@ var Logger = require("./logger"); var Config = require("./config"); var db = require("./database"); +var Promise = require("bluebird"); var init = null; @@ -61,14 +62,13 @@ function initChannelDumper(Server) { var CHANNEL_SAVE_INTERVAL = parseInt(Config.get("channel-save-interval")) * 60000; setInterval(function () { - for (var i = 0; i < Server.channels.length; i++) { - var chan = Server.channels[i]; + Promise.reduce(Server.channels, (_, chan) => { if (!chan.dead && chan.users && chan.users.length > 0) { - chan.saveState().catch(err => { + return chan.saveState().catch(err => { Logger.errlog.log(`Failed to save /r/${chan.name}: ${err.stack}`); }); } - } + }, 0); }, CHANNEL_SAVE_INTERVAL); }