From 755cc74170d3640f4004cb2be582856a9e3936fd Mon Sep 17 00:00:00 2001 From: jomo Date: Sun, 30 Aug 2015 04:48:50 +0200 Subject: [PATCH] don't update file dates this was originally implemented because we wanted to delete the oldest images on disk where 'oldest' means not *used* for the longest time that's not useful and was never actually implemented, so we don't need this --- lib/cache.js | 25 ++----------------------- lib/helpers.js | 6 +++--- test/test.js | 8 -------- 3 files changed, 5 insertions(+), 34 deletions(-) diff --git a/lib/cache.js b/lib/cache.js index e8b7d72..0c04c67 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -36,26 +36,6 @@ function connect_redis() { }); } -// sets the date of the face file belonging to +skin_hash+ to now -// the helms file is ignored because we only need 1 file to read/write from -function update_file_date(rid, skin_hash) { - if (skin_hash) { - var face_path = path.join(config.directories.faces, skin_hash + ".png"); - fs.exists(face_path, function(exists) { - if (exists) { - var date = new Date(); - fs.utimes(face_path, date, date, function(err) { - if (err) { - logging.error(rid, "Error:", err.stack); - } - }); - } else { - logging.error(rid, "tried to update", face_path + " date, but it does not exist"); - } - }); - } -} - var exp = {}; // returns the redis instance @@ -92,11 +72,11 @@ exp.info = function(callback) { }); }; -// sets the timestamp for +userId+ and its face file's (+hash+) date to the current time +// sets the timestamp for +userId+ // if +temp+ is true, the timestamp is set so that the record will be outdated after 60 seconds // these 60 seconds match the duration of Mojang's rate limit ban // callback: error -exp.update_timestamp = function(rid, userId, hash, temp, callback) { +exp.update_timestamp = function(rid, userId, temp, callback) { logging.debug(rid, "updating cache timestamp"); var sub = temp ? config.caching.local - 60 : 0; var time = Date.now() - sub; @@ -105,7 +85,6 @@ exp.update_timestamp = function(rid, userId, hash, temp, callback) { redis.hmset(userId, "t", time, function(err) { callback(err); }); - update_file_date(rid, hash); }; // create the key +userId+, store +skin_hash+, +cape_hash+ and time diff --git a/lib/helpers.js b/lib/helpers.js index c76a319..04f9d07 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -25,7 +25,7 @@ function store_skin(rid, userId, profile, cache_details, callback) { if (!err && url) { var skin_hash = get_hash(url); if (cache_details && cache_details.skin === skin_hash) { - cache.update_timestamp(rid, userId, skin_hash, false, function(cache_err) { + cache.update_timestamp(rid, userId, false, function(cache_err) { callback(cache_err, skin_hash); }); } else { @@ -82,7 +82,7 @@ function store_cape(rid, userId, profile, cache_details, callback) { if (!err && url) { var cape_hash = get_hash(url); if (cache_details && cache_details.cape === cape_hash) { - cache.update_timestamp(rid, userId, cape_hash, false, function(cache_err) { + cache.update_timestamp(rid, userId, false, function(cache_err) { callback(cache_err, cape_hash); }); } else { @@ -238,7 +238,7 @@ exp.get_image_hash = function(rid, userId, type, callback) { if (store_err) { // we might have a cached hash although an error occured // (e.g. Mojang servers not reachable, using outdated hash) - cache.update_timestamp(rid, userId, cached_hash, true, function(err2) { + cache.update_timestamp(rid, userId, true, function(err2) { callback(err2 || store_err, -1, cache_details && cached_hash); }); } else { diff --git a/test/test.js b/test/test.js index 8bfd808..ad23e94 100644 --- a/test/test.js +++ b/test/test.js @@ -204,14 +204,6 @@ describe("Crafatar", function() { }); }); }); - it("should ignore file updates on invalid files", function(done) { - assert.doesNotThrow(function() { - cache.update_timestamp(rid, "0123456789abcdef0123456789abcdef", "invalid-file.png", false, function(err) { - assert.ifError(err); - done(); - }); - }); - }); it("should not find the file", function(done) { skins.open_skin(rid, "non/existent/path", function(err, img) { assert(err);