diff --git a/store/buildMatch.js b/store/buildMatch.js index 4ece5afd6..3bea9d154 100644 --- a/store/buildMatch.js +++ b/store/buildMatch.js @@ -7,6 +7,7 @@ var queries = require('./queries'); var compute = require('../util/compute'); var utility = require('../util/utility'); var benchmarkMatch = queries.benchmarkMatch; +var getMatchRating = queries.getMatchRating; var computeMatchData = compute.computeMatchData; var renderMatch = compute.renderMatch; var deserialize = utility.deserialize; @@ -231,34 +232,4 @@ function getMatch(db, redis, match_id, options, cb) } } } - -function getMatchRating(redis, match, cb) -{ - async.map(match.players, function(player, cb) - { - if (!player.account_id) - { - return cb(); - } - redis.zscore('solo_competitive_rank', player.account_id, cb); - }, function(err, result) - { - if (err) - { - return cb(err); - } - var filt = result.filter(function(r) - { - return r; - }); - var avg = ~~(filt.map(function(r) - { - return Number(r); - }).reduce(function(a, b) - { - return a + b; - }, 0) / filt.length); - cb(err, avg); - }); -} module.exports = buildMatch; \ No newline at end of file diff --git a/store/queries.js b/store/queries.js index f7f165675..32ec71c5a 100644 --- a/store/queries.js +++ b/store/queries.js @@ -491,6 +491,36 @@ function benchmarkMatch(redis, m, cb) }, cb); } +function getMatchRating(redis, match, cb) +{ + async.map(match.players, function(player, cb) + { + if (!player.account_id) + { + return cb(); + } + redis.zscore('solo_competitive_rank', player.account_id, cb); + }, function(err, result) + { + if (err) + { + return cb(err); + } + var filt = result.filter(function(r) + { + return r; + }); + var avg = ~~(filt.map(function(r) + { + return Number(r); + }).reduce(function(a, b) + { + return a + b; + }, 0) / filt.length); + cb(err, avg); + }); +} + function getDistributions(redis, cb) { var keys = ["distribution:mmr", "distribution:country_mmr"]; @@ -862,6 +892,7 @@ module.exports = { getHeroRankings, getBenchmarks, benchmarkMatch, + getMatchRating, upsert, getLeaderboard, mmrEstimate, diff --git a/svc/web.js b/svc/web.js index b782a4c21..ba3590308 100644 --- a/svc/web.js +++ b/svc/web.js @@ -93,17 +93,6 @@ var sessOptions = { app.use(session(sessOptions)); app.use(passport.initialize()); app.use(passport.session()); -app.use(function(req, res, next) -{ - if (req.headers.host.match(/^www/) !== null) - { - res.redirect(req.protocol + '://' + req.headers.host.replace(/^www\./, '') + req.url); - } - else - { - next(); - } -}); app.use(function rateLimit(req, res, cb) { var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || ""; @@ -219,11 +208,6 @@ app.use('/api', api(db, redis, cassandra)); //TODO remove these with SPA app.route('/').get(function(req, res, next) { - if (config.UI_HOST) - { - return res.redirect(config.UI_HOST); - } - //TODO remove this with SPA if (req.user) { res.redirect('/players/' + req.user.account_id); @@ -403,6 +387,10 @@ app.use('/', mmstats(redis)); app.use('/', donate(db, redis)); app.use(function(req, res, next) { + if (config.UI_HOST) + { + return res.redirect(config.UI_HOST + req.url); + } var err = new Error("Not Found"); err.status = 404; return next(err);