Fix and use thread.collect for GC

Also merge appchan's JSON option fixes
This commit is contained in:
Zixaphir 2014-01-14 17:18:30 -07:00
parent bcd7ab21e3
commit 481ca6af72
6 changed files with 109 additions and 100 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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 = {}

View File

@ -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[@]