From 481ca6af725b89321be25478326748697c0c2a87 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Tue, 14 Jan 2014 17:18:30 -0700 Subject: [PATCH] Fix and use thread.collect for GC Also merge appchan's JSON option fixes --- LICENSE | 2 +- builds/4chan-X.user.js | 80 +++++++++++++++++++----------------- builds/crx/script.js | 80 +++++++++++++++++++----------------- src/General/Main.coffee | 39 ++++++++++-------- src/General/Navigate.coffee | 5 +-- src/General/lib/thread.class | 3 +- 6 files changed, 109 insertions(+), 100 deletions(-) diff --git a/LICENSE b/LICENSE index 5b61dddf7..c3a9eca17 100755 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* 4chan X - Version 1.3.2 - 2014-01-13 +* 4chan X - Version 1.3.2 - 2014-01-14 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 433af2b54..59ba54363 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -22,7 +22,7 @@ // ==/UserScript== /* -* 4chan X - Version 1.3.2 - 2014-01-13 +* 4chan X - Version 1.3.2 - 2014-01-14 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -949,10 +949,10 @@ }; Thread.prototype.collect = function() { - var post, postID, _i, _len, _ref; + var post, postID, _ref; _ref = this.posts; - for (post = _i = 0, _len = _ref.length; _i < _len; post = ++_i) { - postID = _ref[post]; + for (postID in _ref) { + post = _ref[postID]; post.collect(); } delete g.threads[this.fullID]; @@ -11924,12 +11924,13 @@ } }, clean: function() { - var posts, threads; + var id, posts, thread, threads, _ref; posts = g.posts, threads = g.threads; - g.posts = {}; - g.threads = {}; - g.BOARD.posts = {}; - g.BOARD.threads = {}; + _ref = g.threads; + for (id in _ref) { + thread = _ref[id]; + thread.collect(); + } QuoteBacklink.containers = {}; return $.rmAll($('.board')); }, @@ -13033,7 +13034,7 @@ }); $.before(styleSelector.previousSibling, [$.tn('['), passLink, $.tn(']\u00A0\u00A0')]); } - if (g.VIEW === 'thread') { + if (!(Conf['JSON Navigation'] && g.VIEW === 'index')) { Main.initThread(); } else { $.event('4chanXInitFinished'); @@ -13056,37 +13057,40 @@ } }, initThread: function() { - var err, errors, postRoot, posts, thread, threadRoot, _i, _len, _ref; - if (!(threadRoot = $('.thread'))) { - return; - } - thread = new Thread(+threadRoot.id.slice(1), g.BOARD); - posts = []; - _ref = $$('.thread > .postContainer', threadRoot); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - postRoot = _ref[_i]; - try { - posts.push(new Post(postRoot, thread, g.BOARD, { - isOriginalMarkup: true - })); - } catch (_error) { - err = _error; - if (!errors) { - errors = []; + var board, err, errors, postRoot, posts, thread, threadRoot, threads, _i, _j, _len, _len1, _ref, _ref1; + if (board = $('.board')) { + threads = []; + posts = []; + _ref = $$('.board > .thread', board); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + threadRoot = _ref[_i]; + thread = new Thread(+threadRoot.id.slice(1), g.BOARD); + threads.push(thread); + _ref1 = $$('.thread > .postContainer', threadRoot); + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + postRoot = _ref1[_j]; + try { + posts.push(new Post(postRoot, thread, g.BOARD)); + } catch (_error) { + err = _error; + if (!errors) { + errors = []; + } + errors.push({ + message: "Parsing of Post No." + (postRoot.id.match(/\d+/)) + " failed. Post will be skipped.", + error: err + }); + } } - errors.push({ - message: "Parsing of Post No." + (postRoot.id.match(/\d+/)) + " failed. Post will be skipped.", - error: err - }); } + if (errors) { + Main.handleErrors(errors); + } + Main.callbackNodes(Thread, threads); + return Main.callbackNodesDB(Post, posts, function() { + return $.event('4chanXInitFinished'); + }); } - if (errors) { - Main.handleErrors(errors); - } - Main.callbackNodes(Thread, [thread]); - return Main.callbackNodesDB(Post, posts, function() { - return $.event('4chanXInitFinished'); - }); }, callbackNodes: function(klass, nodes) { var cb, i, node; diff --git a/builds/crx/script.js b/builds/crx/script.js index eb9650742..ed2fe23e3 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript /* -* 4chan X - Version 1.3.2 - 2014-01-13 +* 4chan X - Version 1.3.2 - 2014-01-14 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -954,10 +954,10 @@ }; Thread.prototype.collect = function() { - var post, postID, _i, _len, _ref; + var post, postID, _ref; _ref = this.posts; - for (post = _i = 0, _len = _ref.length; _i < _len; post = ++_i) { - postID = _ref[post]; + for (postID in _ref) { + post = _ref[postID]; post.collect(); } delete g.threads[this.fullID]; @@ -11913,12 +11913,13 @@ } }, clean: function() { - var posts, threads; + var id, posts, thread, threads, _ref; posts = g.posts, threads = g.threads; - g.posts = {}; - g.threads = {}; - g.BOARD.posts = {}; - g.BOARD.threads = {}; + _ref = g.threads; + for (id in _ref) { + thread = _ref[id]; + thread.collect(); + } QuoteBacklink.containers = {}; return $.rmAll($('.board')); }, @@ -13020,7 +13021,7 @@ }); $.before(styleSelector.previousSibling, [$.tn('['), passLink, $.tn(']\u00A0\u00A0')]); } - if (g.VIEW === 'thread') { + if (!(Conf['JSON Navigation'] && g.VIEW === 'index')) { Main.initThread(); } else { $.event('4chanXInitFinished'); @@ -13033,37 +13034,40 @@ } }, initThread: function() { - var err, errors, postRoot, posts, thread, threadRoot, _i, _len, _ref; - if (!(threadRoot = $('.thread'))) { - return; - } - thread = new Thread(+threadRoot.id.slice(1), g.BOARD); - posts = []; - _ref = $$('.thread > .postContainer', threadRoot); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - postRoot = _ref[_i]; - try { - posts.push(new Post(postRoot, thread, g.BOARD, { - isOriginalMarkup: true - })); - } catch (_error) { - err = _error; - if (!errors) { - errors = []; + var board, err, errors, postRoot, posts, thread, threadRoot, threads, _i, _j, _len, _len1, _ref, _ref1; + if (board = $('.board')) { + threads = []; + posts = []; + _ref = $$('.board > .thread', board); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + threadRoot = _ref[_i]; + thread = new Thread(+threadRoot.id.slice(1), g.BOARD); + threads.push(thread); + _ref1 = $$('.thread > .postContainer', threadRoot); + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + postRoot = _ref1[_j]; + try { + posts.push(new Post(postRoot, thread, g.BOARD)); + } catch (_error) { + err = _error; + if (!errors) { + errors = []; + } + errors.push({ + message: "Parsing of Post No." + (postRoot.id.match(/\d+/)) + " failed. Post will be skipped.", + error: err + }); + } } - errors.push({ - message: "Parsing of Post No." + (postRoot.id.match(/\d+/)) + " failed. Post will be skipped.", - error: err - }); } + if (errors) { + Main.handleErrors(errors); + } + Main.callbackNodes(Thread, threads); + return Main.callbackNodesDB(Post, posts, function() { + return $.event('4chanXInitFinished'); + }); } - if (errors) { - Main.handleErrors(errors); - } - Main.callbackNodes(Thread, [thread]); - return Main.callbackNodesDB(Post, posts, function() { - return $.event('4chanXInitFinished'); - }); }, callbackNodes: function(klass, nodes) { var cb, i, node; diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 5eda4422d..7ccb225ac 100755 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -131,7 +131,7 @@ Main = 'left=0,top=0,width=500,height=255,toolbar=0,resizable=0' $.before styleSelector.previousSibling, [$.tn '['; passLink, $.tn ']\u00A0\u00A0'] - if g.VIEW is 'thread' + unless Conf['JSON Navigation'] and g.VIEW is 'index' Main.initThread() else $.event '4chanXInitFinished' @@ -150,23 +150,28 @@ Main = new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30 initThread: -> - return unless threadRoot = $ '.thread' - thread = new Thread +threadRoot.id[1..], g.BOARD - posts = [] - for postRoot in $$ '.thread > .postContainer', threadRoot - try - posts.push new Post postRoot, thread, g.BOARD, {isOriginalMarkup: true} - catch err - # Skip posts that we failed to parse. - errors = [] unless errors - errors.push - message: "Parsing of Post No.#{postRoot.id.match /\d+/} failed. Post will be skipped." - error: err - Main.handleErrors errors if errors + if board = $ '.board' + threads = [] + posts = [] - Main.callbackNodes Thread, [thread] - Main.callbackNodesDB Post, posts, -> - $.event '4chanXInitFinished' + for threadRoot in $$ '.board > .thread', board + thread = new Thread +threadRoot.id[1..], g.BOARD + threads.push thread + for postRoot in $$ '.thread > .postContainer', threadRoot + try + posts.push new Post postRoot, thread, g.BOARD + catch err + # Skip posts that we failed to parse. + unless errors + errors = [] + errors.push + message: "Parsing of Post No.#{postRoot.id.match(/\d+/)} failed. Post will be skipped." + error: err + Main.handleErrors errors if errors + + Main.callbackNodes Thread, threads + Main.callbackNodesDB Post, posts, -> + $.event '4chanXInitFinished' callbackNodes: (klass, nodes) -> i = 0 diff --git a/src/General/Navigate.coffee b/src/General/Navigate.coffee index 63806eb3a..43659ebc9 100644 --- a/src/General/Navigate.coffee +++ b/src/General/Navigate.coffee @@ -34,10 +34,7 @@ Navigate = {posts, threads} = g # Garbage collection - g.posts = {} - g.threads = {} - g.BOARD.posts = {} - g.BOARD.threads = {} + thread.collect() for id, thread of g.threads QuoteBacklink.containers = {} diff --git a/src/General/lib/thread.class b/src/General/lib/thread.class index 395e06eb6..da1bfbb03 100755 --- a/src/General/lib/thread.class +++ b/src/General/lib/thread.class @@ -44,7 +44,6 @@ class Thread @timeOfDeath = Date.now() collect: -> - for postID, post in @posts - post.collect() + post.collect() for postID, post of @posts delete g.threads[@fullID] delete @board.threads[@]