From cb39424deac8227ee6bc5571ff5a01f18a8e081e Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sat, 11 Jan 2014 17:19:19 -0700 Subject: [PATCH 1/2] Reduce number of loops in Redirect --- builds/4chan-X.user.js | 32 ++++++++++++++------------------ builds/crx/script.js | 32 ++++++++++++++------------------ src/Archive/Redirect.coffee | 12 +++++------- 3 files changed, 33 insertions(+), 43 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index cf6d4daab..67e359df8 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -10002,7 +10002,7 @@ Redirect = { init: function() { - var archive, archives, boardID, boards, data, files, id, name, o, record, software, type, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3, _ref4; + var archive, archives, boardID, boards, data, files, id, name, o, record, software, type, _i, _j, _len, _len1, _ref, _ref1, _ref2; o = { thread: {}, post: {}, @@ -10017,6 +10017,19 @@ files: files, data: data }; + software = data.software; + for (_j = 0, _len1 = boards.length; _j < _len1; _j++) { + boardID = boards[_j]; + if (!(boardID in o.thread)) { + o.thread[boardID] = data; + } + if (!(boardID in o.post || software !== 'foolfuuka')) { + o.post[boardID] = data; + } + if (!(boardID in o.file || __indexOf.call(files, boardID) < 0)) { + o.file[boardID] = data; + } + } } _ref2 = Conf['selectedArchives']; for (boardID in _ref2) { @@ -10033,23 +10046,6 @@ o[type][boardID] = archive.data; } } - _ref3 = Redirect.archives; - for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) { - _ref4 = _ref3[_j], data = _ref4.data, boards = _ref4.boards, files = _ref4.files; - software = data.software; - for (_k = 0, _len2 = boards.length; _k < _len2; _k++) { - boardID = boards[_k]; - if (!(boardID in o.thread)) { - o.thread[boardID] = data; - } - if (!(boardID in o.post || software !== 'foolfuuka')) { - o.post[boardID] = data; - } - if (!(boardID in o.file || __indexOf.call(files, boardID) < 0)) { - o.file[boardID] = data; - } - } - } return Redirect.data = o; }, archives: [ diff --git a/builds/crx/script.js b/builds/crx/script.js index f5f1086f1..6d7b4d763 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -9991,7 +9991,7 @@ Redirect = { init: function() { - var archive, archives, boardID, boards, data, files, id, name, o, record, software, type, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3, _ref4; + var archive, archives, boardID, boards, data, files, id, name, o, record, software, type, _i, _j, _len, _len1, _ref, _ref1, _ref2; o = { thread: {}, post: {}, @@ -10006,6 +10006,19 @@ files: files, data: data }; + software = data.software; + for (_j = 0, _len1 = boards.length; _j < _len1; _j++) { + boardID = boards[_j]; + if (!(boardID in o.thread)) { + o.thread[boardID] = data; + } + if (!(boardID in o.post || software !== 'foolfuuka')) { + o.post[boardID] = data; + } + if (!(boardID in o.file || __indexOf.call(files, boardID) < 0)) { + o.file[boardID] = data; + } + } } _ref2 = Conf['selectedArchives']; for (boardID in _ref2) { @@ -10022,23 +10035,6 @@ o[type][boardID] = archive.data; } } - _ref3 = Redirect.archives; - for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) { - _ref4 = _ref3[_j], data = _ref4.data, boards = _ref4.boards, files = _ref4.files; - software = data.software; - for (_k = 0, _len2 = boards.length; _k < _len2; _k++) { - boardID = boards[_k]; - if (!(boardID in o.thread)) { - o.thread[boardID] = data; - } - if (!(boardID in o.post || software !== 'foolfuuka')) { - o.post[boardID] = data; - } - if (!(boardID in o.file || __indexOf.call(files, boardID) < 0)) { - o.file[boardID] = data; - } - } - } return Redirect.data = o; }, archives: [ diff --git a/src/Archive/Redirect.coffee b/src/Archive/Redirect.coffee index ea2e26d70..06ac8f37f 100755 --- a/src/Archive/Redirect.coffee +++ b/src/Archive/Redirect.coffee @@ -9,6 +9,11 @@ Redirect = archives = {} for {name, boards, files, data} in Redirect.archives archives[name] = {boards, files, data} + {software} = data + for boardID in boards + o.thread[boardID] = data unless boardID of o.thread + o.post[boardID] = data unless boardID of o.post or software isnt 'foolfuuka' + o.file[boardID] = data unless boardID of o.file or boardID not in files for boardID, record of Conf['selectedArchives'] for type, id of record when (archive = archives[id]) @@ -16,13 +21,6 @@ Redirect = continue unless boardID in boards o[type][boardID] = archive.data - for {data, boards, files} in Redirect.archives - {software} = data - for boardID in boards - o.thread[boardID] = data unless boardID of o.thread - o.post[boardID] = data unless boardID of o.post or software isnt 'foolfuuka' - o.file[boardID] = data unless boardID of o.file or boardID not in files - Redirect.data = o archives: [ From 495567682b97bed58e750574e305f87d8f9c1035 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sat, 11 Jan 2014 19:34:07 -0700 Subject: [PATCH 2/2] Fix duplicate backlinks --- builds/4chan-X.user.js | 3 ++- builds/crx/script.js | 3 ++- src/General/Navigate.coffee | 2 ++ src/Quotelinks/QuoteBacklink.coffee | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 67e359df8..91e08a981 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -4690,6 +4690,7 @@ }; QuoteBacklink = { + containers: {}, init: function() { var format; if (g.VIEW === 'catalog' || !Conf['Quote Backlinks']) { @@ -4697,7 +4698,6 @@ } format = Conf['backlink'].replace(/%id/g, "' + id + '"); this.funk = Function('id', "return '" + format + "'"); - this.containers = {}; Post.callbacks.push({ name: 'Quote Backlinking Part 1', cb: this.firstNode @@ -11935,6 +11935,7 @@ g.threads = {}; g.BOARD.posts = {}; g.BOARD.threads = {}; + QuoteBacklink.containers = {}; return $.rmAll($('.board')); }, features: [['Thread Excerpt', ThreadExcerpt], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats], ['Thread Updater', ThreadUpdater], ['Thread Expansion', ExpandThread]], diff --git a/builds/crx/script.js b/builds/crx/script.js index 6d7b4d763..70499ee45 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -4693,6 +4693,7 @@ }; QuoteBacklink = { + containers: {}, init: function() { var format; if (g.VIEW === 'catalog' || !Conf['Quote Backlinks']) { @@ -4700,7 +4701,6 @@ } format = Conf['backlink'].replace(/%id/g, "' + id + '"); this.funk = Function('id', "return '" + format + "'"); - this.containers = {}; Post.callbacks.push({ name: 'Quote Backlinking Part 1', cb: this.firstNode @@ -11924,6 +11924,7 @@ g.threads = {}; g.BOARD.posts = {}; g.BOARD.threads = {}; + QuoteBacklink.containers = {}; return $.rmAll($('.board')); }, features: [['Thread Excerpt', ThreadExcerpt], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats], ['Thread Updater', ThreadUpdater], ['Thread Expansion', ExpandThread]], diff --git a/src/General/Navigate.coffee b/src/General/Navigate.coffee index 19ade13c0..02a1c60fe 100644 --- a/src/General/Navigate.coffee +++ b/src/General/Navigate.coffee @@ -34,6 +34,8 @@ Navigate = g.BOARD.posts = {} g.BOARD.threads = {} + QuoteBacklink.containers = {} + # Delete nodes $.rmAll $ '.board' diff --git a/src/Quotelinks/QuoteBacklink.coffee b/src/Quotelinks/QuoteBacklink.coffee index 2b5aa2342..a9665b25d 100755 --- a/src/Quotelinks/QuoteBacklink.coffee +++ b/src/Quotelinks/QuoteBacklink.coffee @@ -10,12 +10,12 @@ QuoteBacklink = # Second callback adds relevant containers into posts. # This is is so that fetched posts can get their backlinks, # and that as much backlinks are appended in the background as possible. + containers: {} init: -> return if g.VIEW is 'catalog' or !Conf['Quote Backlinks'] format = Conf['backlink'].replace /%id/g, "' + id + '" @funk = Function 'id', "return '#{format}'" - @containers = {} Post.callbacks.push name: 'Quote Backlinking Part 1' cb: @firstNode