From 473b8e879eb6d81eaa55ff241accbbe85ab85c4c Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sun, 2 Mar 2014 19:03:50 -0700 Subject: [PATCH] Implement a shitty cache for QuoteMarkers --- builds/4chan-X.user.js | 13 +++++++++---- builds/crx/script.js | 13 +++++++++---- src/Quotelinks/QuoteMarkers.coffee | 12 ++++++++++-- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index a87d9e9e2..75fdd5717 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -5389,18 +5389,23 @@ }); }, node: function() { - var quotelink, _i, _len, _ref; + var parseQuotelink, quotelink, _i, _len, _ref; + parseQuotelink = QuoteMarkers.parseQuotelink; _ref = this.nodes.quotelinks; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quotelink = _ref[_i]; - QuoteMarkers.parseQuotelink(this, quotelink, !!this.isClone); + parseQuotelink(this, quotelink, !!this.isClone); } }, + cache: {}, parseQuotelink: function(post, quotelink, mayReset, customText) { - var board, boardID, markers, postID, text, thread, threadID, _ref, _ref1, _ref2; + var board, boardID, cache, markers, postID, text, thread, threadID, _ref, _ref1, _ref2; _ref = post.isClone ? post.context : post, board = _ref.board, thread = _ref.thread; markers = []; _ref1 = Get.postDataFromLink(quotelink), boardID = _ref1.boardID, threadID = _ref1.threadID, postID = _ref1.postID; + if (cache = QuoteMarkers.cache[postID]) { + quotelink.textContent = cache; + } if ((_ref2 = QR.db) != null ? _ref2.get({ boardID: boardID, threadID: threadID, @@ -5421,7 +5426,7 @@ } text = customText ? customText : boardID === post.board.ID ? ">>" + postID : ">>>/" + boardID + "/" + postID; if (markers.length) { - return quotelink.textContent = "" + text + "\u00A0(" + (markers.join('/')) + ")"; + return quotelink.textContent = "" + text + "\u00A0(" + (markers.join('|')) + ")"; } else if (mayReset) { return quotelink.textContent = text; } diff --git a/builds/crx/script.js b/builds/crx/script.js index d1fada890..690566638 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -5441,18 +5441,23 @@ }); }, node: function() { - var quotelink, _i, _len, _ref; + var parseQuotelink, quotelink, _i, _len, _ref; + parseQuotelink = QuoteMarkers.parseQuotelink; _ref = this.nodes.quotelinks; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quotelink = _ref[_i]; - QuoteMarkers.parseQuotelink(this, quotelink, !!this.isClone); + parseQuotelink(this, quotelink, !!this.isClone); } }, + cache: {}, parseQuotelink: function(post, quotelink, mayReset, customText) { - var board, boardID, markers, postID, text, thread, threadID, _ref, _ref1, _ref2; + var board, boardID, cache, markers, postID, text, thread, threadID, _ref, _ref1, _ref2; _ref = post.isClone ? post.context : post, board = _ref.board, thread = _ref.thread; markers = []; _ref1 = Get.postDataFromLink(quotelink), boardID = _ref1.boardID, threadID = _ref1.threadID, postID = _ref1.postID; + if (cache = QuoteMarkers.cache[postID]) { + quotelink.textContent = cache; + } if ((_ref2 = QR.db) != null ? _ref2.get({ boardID: boardID, threadID: threadID, @@ -5473,7 +5478,7 @@ } text = customText ? customText : boardID === post.board.ID ? ">>" + postID : ">>>/" + boardID + "/" + postID; if (markers.length) { - return quotelink.textContent = "" + text + "\u00A0(" + (markers.join('/')) + ")"; + return quotelink.textContent = "" + text + "\u00A0(" + (markers.join('|')) + ")"; } else if (mayReset) { return quotelink.textContent = text; } diff --git a/src/Quotelinks/QuoteMarkers.coffee b/src/Quotelinks/QuoteMarkers.coffee index fe6a66d4a..88235c4b0 100644 --- a/src/Quotelinks/QuoteMarkers.coffee +++ b/src/Quotelinks/QuoteMarkers.coffee @@ -5,14 +5,22 @@ QuoteMarkers = Post.callbacks.push name: 'Quote Markers' cb: @node + node: -> + {parseQuotelink} = QuoteMarkers for quotelink in @nodes.quotelinks - QuoteMarkers.parseQuotelink @, quotelink, !!@isClone + parseQuotelink @, quotelink, !!@isClone return + + cache: {} + parseQuotelink: (post, quotelink, mayReset, customText) -> {board, thread} = if post.isClone then post.context else post markers = [] {boardID, threadID, postID} = Get.postDataFromLink quotelink + + if cache = QuoteMarkers.cache[postID] + quotelink.textContent = cache if QR.db?.get {boardID, threadID, postID} markers.push 'You' @@ -34,6 +42,6 @@ QuoteMarkers = else ">>>/#{boardID}/#{postID}" if markers.length - quotelink.textContent = "#{text}\u00A0(#{markers.join '/'})" + quotelink.textContent = "#{text}\u00A0(#{markers.join '|'})" else if mayReset quotelink.textContent = text