Permalink
Browse files

Moved clear cache file to shared

  • Loading branch information...
1 parent 5e115e5 commit d64db4de0524b20b9979a102dfb11308833cf1a4 @Sembiance Sembiance committed Jul 10, 2014
Showing with 24 additions and 15 deletions.
  1. +15 −0 shared/shared.js
  2. +9 −15 util/clearCacheForSet.js
View
@@ -3,6 +3,9 @@
var base = require("xbase"),
C = require("C"),
+ hash = require("mhash").hash,
+ path = require("path"),
+ fs = require("fs"),
url = require("url"),
unicodeUtil = require("xutil").unicode;
@@ -196,3 +199,15 @@ exports.performSetCorrections = function(setCorrections, cards)
});
});
};
+
+exports.clearCacheFile = function(targetUrl, cb)
+{
+ var urlHash = hash("whirlpool", targetUrl);
+ var cachePath = path.join(__dirname, "..", "cache", urlHash.charAt(0), urlHash);
+ if(!fs.existsSync(cachePath))
+ return setImmediate(cb);
+
+ base.info("Clearing: %s for %s", urlHash, targetUrl);
+
+ fs.unlink(cachePath, cb);
+};
View
@@ -8,7 +8,7 @@ var base = require("xbase"),
request = require("request"),
url = require("url"),
shared = require("shared"),
- hash = require("mhash").hash,
+ querystring = require("querystring"),
fileUtil = require("xutil").file,
path = require("path"),
tiptoe = require("tiptoe");
@@ -91,7 +91,7 @@ function clearCacheForSet(code, cacheType, cb)
if(cacheType==="printings")
this.data.urls = this.data.urls.concat(Array.prototype.slice.apply(arguments).flatten().uniqueBySort());
- this.data.urls.serialForEach(clearCacheFile, this);
+ this.data.urls.serialForEach(shared.clearCacheFile, this);
},
function finish(err)
{
@@ -100,18 +100,6 @@ function clearCacheForSet(code, cacheType, cb)
);
}
-function clearCacheFile(targetUrl, cb)
-{
- var urlHash = hash("whirlpool", targetUrl);
- var cachePath = path.join(__dirname, "..", "cache", urlHash.charAt(0), urlHash);
- if(!fs.existsSync(cachePath))
- return setImmediate(cb);
-
- base.info("Clearing: %s for %s", urlHash, targetUrl);
-
- fs.unlink(cachePath, cb);
-}
-
function buildMultiverseAllPrintingsURL(multiverseid, cb)
{
tiptoe(
@@ -126,8 +114,14 @@ function buildMultiverseAllPrintingsURL(multiverseid, cb)
var urls = [];
var doc = cheerio.load(pageHTML);
+
var pageLinks = doc("#ctl00_ctl00_ctl00_MainContent_SubContent_SubContent_PrintingsList_pagingControlsContainer a").map(function(i, item) { return doc(item); });
- var numPages = pageLinks.length>0 ? pageLinks.length : 1;
+ var numPages = 1;
+ if(pageLinks.length>0)
+ {
+ var lastPageHREF = pageLinks.last().attr("href");
+ numPages += +querystring.parse(lastPageHREF.substring(lastPageHREF.indexOf("?")+1)).page;
+ }
for(var i=0;i<numPages;i++)
{
urls.push(shared.buildMultiversePrintingsURL(multiverseid, i));

0 comments on commit d64db4d

Please sign in to comment.