From 2d6af31c00ab95216813a30e738b28925f7336e7 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Sun, 11 Nov 2018 16:08:00 -0800 Subject: [PATCH] voteskip: add early exit for duplicate votes --- package.json | 2 +- src/channel/voteskip.js | 5 ++++- src/poll.js | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ae327403..a8c53ea7 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.60.0", + "version": "3.60.1", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/src/channel/voteskip.js b/src/channel/voteskip.js index 608c970a..296e49b3 100644 --- a/src/channel/voteskip.js +++ b/src/channel/voteskip.js @@ -40,7 +40,10 @@ VoteskipModule.prototype.handleVoteskip = function (user) { this.poll = new Poll("[server]", "voteskip", ["skip"], false); } - this.poll.vote(user.realip, 0); + if (!this.poll.vote(user.realip, 0)) { + // Vote was already recorded for this IP, no update needed + return; + } var title = ""; if (this.channel.modules.playlist.current) { diff --git a/src/poll.js b/src/poll.js index 43dafc82..3ae5ccb7 100644 --- a/src/poll.js +++ b/src/poll.js @@ -24,7 +24,9 @@ Poll.prototype.vote = function(ip, option) { if(!(ip in this.votes) || this.votes[ip] == null) { this.votes[ip] = option; this.counts[option]++; + return true; } + return false; }; Poll.prototype.unvote = function(ip) {