فهرست منبع

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
jomo 9 سال پیش
والد
کامیت
755cc74170
3فایلهای تغییر یافته به همراه5 افزوده شده و 34 حذف شده
  1. 2 23
      lib/cache.js
  2. 3 3
      lib/helpers.js
  3. 0 8
      test/test.js

+ 2 - 23
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

+ 3 - 3
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 {

+ 0 - 8
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);