From c79bb318b24ec00e2cb3c0bfb592dd0d3ad41bd3 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 5 Apr 2013 00:16:42 +0200 Subject: [PATCH] Cache requests to threads.json. --- lib/$.coffee | 4 ++-- src/databoard.coffee | 2 +- src/features.coffee | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/$.coffee b/lib/$.coffee index a63573fbd..30f26b20d 100644 --- a/lib/$.coffee +++ b/lib/$.coffee @@ -63,8 +63,8 @@ $.extend $, return rm = -> delete reqs[url] req = $.ajax url, - onload: -> - cb.call @ for cb in @callbacks + onload: (e) -> + cb.call @, e for cb in @callbacks delete @callbacks onabort: rm onerror: rm diff --git a/src/databoard.coffee b/src/databoard.coffee index 26743c68f..0e41af492 100644 --- a/src/databoard.coffee +++ b/src/databoard.coffee @@ -64,7 +64,7 @@ class DataBoard $.set @key, @data ajaxClean: (boardID) -> - $.ajax "//api.4chan.org/#{boardID}/threads.json", onload: (e) => + $.cache "//api.4chan.org/#{boardID}/threads.json", (e) => if e.target.status is 404 # Deleted board. @delete boardID diff --git a/src/features.coffee b/src/features.coffee index 1e2c981d5..0c7ddba84 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -1111,10 +1111,10 @@ ThreadHiding = # We need to clean hidden threads on the catalog ourselves, # otherwise if we don't visit the catalog regularly # it will pollute the localStorage and our data. - $.ajax "//api.4chan.org/#{g.BOARD}/threads.json", onload: (e) -> + $.cache "//api.4chan.org/#{g.BOARD}/threads.json", -> return unless @status is 200 threads = {} - for page in JSON.parse e.target.response + for page in JSON.parse @response for thread in page.threads if thread.no of hiddenThreadsOnCatalog threads[thread.no] = hiddenThreadsOnCatalog[thread.no]