mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-22 07:51:17 +01:00
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
This commit is contained in:
parent
78f2f2027f
commit
755cc74170
25
lib/cache.js
25
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 = {};
|
var exp = {};
|
||||||
|
|
||||||
// returns the redis instance
|
// 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
|
// 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
|
// these 60 seconds match the duration of Mojang's rate limit ban
|
||||||
// callback: error
|
// 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");
|
logging.debug(rid, "updating cache timestamp");
|
||||||
var sub = temp ? config.caching.local - 60 : 0;
|
var sub = temp ? config.caching.local - 60 : 0;
|
||||||
var time = Date.now() - sub;
|
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) {
|
redis.hmset(userId, "t", time, function(err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
});
|
});
|
||||||
update_file_date(rid, hash);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// create the key +userId+, store +skin_hash+, +cape_hash+ and time
|
// create the key +userId+, store +skin_hash+, +cape_hash+ and time
|
||||||
|
|||||||
@ -25,7 +25,7 @@ function store_skin(rid, userId, profile, cache_details, callback) {
|
|||||||
if (!err && url) {
|
if (!err && url) {
|
||||||
var skin_hash = get_hash(url);
|
var skin_hash = get_hash(url);
|
||||||
if (cache_details && cache_details.skin === skin_hash) {
|
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);
|
callback(cache_err, skin_hash);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -82,7 +82,7 @@ function store_cape(rid, userId, profile, cache_details, callback) {
|
|||||||
if (!err && url) {
|
if (!err && url) {
|
||||||
var cape_hash = get_hash(url);
|
var cape_hash = get_hash(url);
|
||||||
if (cache_details && cache_details.cape === cape_hash) {
|
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);
|
callback(cache_err, cape_hash);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -238,7 +238,7 @@ exp.get_image_hash = function(rid, userId, type, callback) {
|
|||||||
if (store_err) {
|
if (store_err) {
|
||||||
// we might have a cached hash although an error occured
|
// we might have a cached hash although an error occured
|
||||||
// (e.g. Mojang servers not reachable, using outdated hash)
|
// (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);
|
callback(err2 || store_err, -1, cache_details && cached_hash);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -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) {
|
it("should not find the file", function(done) {
|
||||||
skins.open_skin(rid, "non/existent/path", function(err, img) {
|
skins.open_skin(rid, "non/existent/path", function(err, img) {
|
||||||
assert(err);
|
assert(err);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user