2
0
Эх сурвалжийг харах

delete hash from redis if file does not exist

jomo 10 жил өмнө
parent
commit
3a0a23e5b5

+ 5 - 0
modules/cache.js

@@ -107,6 +107,11 @@ exp.save_hash = function(uuid, hash) {
   redis.hmset(uuid, "h", hash, "t", time);
 };
 
+exp.remove_hash = function(uuid) {
+  logging.log(uuid + " cache: deleting hash");
+  redis.del(uuid.toLowerCase(), "h", "t");
+};
+
 // get a details object for +uuid+
 // {hash: "0123456789abcdef", time: 1414881524512}
 // null when uuid unkown

+ 1 - 1
modules/helpers.js

@@ -41,7 +41,7 @@ function store_images(uuid, details, callback) {
             cache.update_timestamp(uuid, hash);
             callback(null, hash);
           } else {
-            if (!exists) {
+            if (details && details.hash && !exists) {
               logging.warn(uuid + " File was deleted! Downloading again.");
             } else {
               // hash has changed

+ 5 - 0
routes/avatars.js

@@ -3,6 +3,7 @@ var logging = require("../modules/logging");
 var helpers = require("../modules/helpers");
 var config = require("../modules/config");
 var skins = require("../modules/skins");
+var cache = require("../modules/cache");
 
 var human_status = {
   0: "none",
@@ -48,6 +49,10 @@ module.exports = function(req, res) {
       logging.log(uuid + " - " + human_status[status]);
       if (err) {
         logging.error(uuid + " " + err);
+        if (err.code == "ENOENT") {
+          logging.warn("Deleting " + uuid + " from cache!");
+          cache.remove_hash(uuid);
+        }
       }
       etag = image && hash && hash.substr(0, 32) || "none";
       var matches = req.headers["if-none-match"] == '"' + etag + '"';