From ba5e9c402c7f106ba4ba7eec19a7fd988c920e81 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Mon, 6 May 2013 00:26:43 -0700 Subject: [PATCH] Prevent updater race conditions. --- LICENSE | 2 +- builds/4chan-X.js | 13 +++++++++++-- builds/4chan-X.user.js | 13 +++++++++++-- builds/crx/script.js | 13 +++++++++++-- src/Monitoring/ThreadUpdater.coffee | 8 +++++++- 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/LICENSE b/LICENSE index ebe5d6533..dfd8af354 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* 4chan X - Version 1.1.9 - 2013-05-05 +* 4chan X - Version 1.1.9 - 2013-05-06 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE diff --git a/builds/4chan-X.js b/builds/4chan-X.js index 073b719f4..31e4a6687 100644 --- a/builds/4chan-X.js +++ b/builds/4chan-X.js @@ -18,7 +18,7 @@ // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAgMAAAAqbBEUAAAACVBMVEUAAGcAAABmzDNZt9VtAAAAAXRSTlMAQObYZgAAAHFJREFUKFOt0LENACEIBdBv4Qju4wgWanEj3D6OcIVMKaitYHEU/jwTCQj8W75kiVCSBvdQ5/AvfVHBin11BgdRq3ysBgfwBDRrj3MCIA+oAQaku/Q1cNctrAmyDl577tOThYt/Y1RBM4DgOHzM0HFTAyLukH/cmRnqAAAAAElFTkSuQmCC // ==/UserScript== /* -* 4chan X - Version 1.1.9 - 2013-05-05 +* 4chan X - Version 1.1.9 - 2013-05-06 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -6885,10 +6885,19 @@ return setTimeout(ThreadUpdater.update, 1000); } }, - checkpost: function() { + checkpost: function(e) { + if (!ThreadUpdater.checkPostCount) { + if (e.detail.threadID !== ThreadUpdater.thread.ID) { + return; + } + ThreadUpdater.seconds = 0; + ThreadUpdater.outdateCount = 0; + ThreadUpdater.set('timer', '...'); + } if (!(g.DEAD || ThreadUpdater.foundPost || ThreadUpdater.checkPostCount >= 5)) { return setTimeout(ThreadUpdater.update, ++ThreadUpdater.checkPostCount * $.SECOND); } + ThreadUpdater.set('timer', ThreadUpdater.getInterval()); ThreadUpdater.checkPostCount = 0; delete ThreadUpdater.foundPost; return delete ThreadUpdater.postID; diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index acadacb17..e19e98147 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -18,7 +18,7 @@ // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAgMAAAAqbBEUAAAACVBMVEUAAGcAAABmzDNZt9VtAAAAAXRSTlMAQObYZgAAAHFJREFUKFOt0LENACEIBdBv4Qju4wgWanEj3D6OcIVMKaitYHEU/jwTCQj8W75kiVCSBvdQ5/AvfVHBin11BgdRq3ysBgfwBDRrj3MCIA+oAQaku/Q1cNctrAmyDl577tOThYt/Y1RBM4DgOHzM0HFTAyLukH/cmRnqAAAAAElFTkSuQmCC // ==/UserScript== /* -* 4chan X - Version 1.1.9 - 2013-05-05 +* 4chan X - Version 1.1.9 - 2013-05-06 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -6906,10 +6906,19 @@ return setTimeout(ThreadUpdater.update, 1000); } }, - checkpost: function() { + checkpost: function(e) { + if (!ThreadUpdater.checkPostCount) { + if (e.detail.threadID !== ThreadUpdater.thread.ID) { + return; + } + ThreadUpdater.seconds = 0; + ThreadUpdater.outdateCount = 0; + ThreadUpdater.set('timer', '...'); + } if (!(g.DEAD || ThreadUpdater.foundPost || ThreadUpdater.checkPostCount >= 5)) { return setTimeout(ThreadUpdater.update, ++ThreadUpdater.checkPostCount * $.SECOND); } + ThreadUpdater.set('timer', ThreadUpdater.getInterval()); ThreadUpdater.checkPostCount = 0; delete ThreadUpdater.foundPost; return delete ThreadUpdater.postID; diff --git a/builds/crx/script.js b/builds/crx/script.js index d78a7f677..ddcc0a052 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,5 +1,5 @@ /* -* 4chan X - Version 1.1.9 - 2013-05-05 +* 4chan X - Version 1.1.9 - 2013-05-06 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -6885,10 +6885,19 @@ return setTimeout(ThreadUpdater.update, 1000); } }, - checkpost: function() { + checkpost: function(e) { + if (!ThreadUpdater.checkPostCount) { + if (e.detail.threadID !== ThreadUpdater.thread.ID) { + return; + } + ThreadUpdater.seconds = 0; + ThreadUpdater.outdateCount = 0; + ThreadUpdater.set('timer', '...'); + } if (!(g.DEAD || ThreadUpdater.foundPost || ThreadUpdater.checkPostCount >= 5)) { return setTimeout(ThreadUpdater.update, ++ThreadUpdater.checkPostCount * $.SECOND); } + ThreadUpdater.set('timer', ThreadUpdater.getInterval()); ThreadUpdater.checkPostCount = 0; delete ThreadUpdater.foundPost; return delete ThreadUpdater.postID; diff --git a/src/Monitoring/ThreadUpdater.coffee b/src/Monitoring/ThreadUpdater.coffee index 2a9ae7d8e..6ed6b005b 100644 --- a/src/Monitoring/ThreadUpdater.coffee +++ b/src/Monitoring/ThreadUpdater.coffee @@ -96,9 +96,15 @@ ThreadUpdater = return unless e.detail.threadID is ThreadUpdater.thread.ID ThreadUpdater.outdateCount = 0 setTimeout ThreadUpdater.update, 1000 if ThreadUpdater.seconds > 2 - checkpost: -> + checkpost: (e) -> + unless ThreadUpdater.checkPostCount + return unless e.detail.threadID is ThreadUpdater.thread.ID + ThreadUpdater.seconds = 0 + ThreadUpdater.outdateCount = 0 + ThreadUpdater.set 'timer', '...' unless g.DEAD or ThreadUpdater.foundPost or ThreadUpdater.checkPostCount >= 5 return setTimeout ThreadUpdater.update, ++ThreadUpdater.checkPostCount * $.SECOND + ThreadUpdater.set 'timer', ThreadUpdater.getInterval() ThreadUpdater.checkPostCount = 0 delete ThreadUpdater.foundPost delete ThreadUpdater.postID