This commit is contained in:
Jake
2014-12-26 00:04:36 -06:00
7 changed files with 130 additions and 142 deletions

View File

@@ -59,6 +59,8 @@ exp.get_redis = function() {
exp.update_timestamp = function(uuid, hash) {
logging.log(uuid + " cache: updating timestamp");
var time = new Date().getTime();
// store uuid in lower case if not null
uuid = uuid && uuid.toLowerCase();
redis.hmset(uuid, "t", time);
update_file_date(hash);
};
@@ -67,6 +69,10 @@ exp.update_timestamp = function(uuid, hash) {
exp.save_hash = function(uuid, hash) {
logging.log(uuid + " cache: saving hash");
var time = new Date().getTime();
// store shorter null byte instead of "null"
hash = hash || ".";
// store uuid in lower case if not null
uuid = uuid && uuid.toLowerCase();
redis.hmset(uuid, "h", hash, "t", time);
};
@@ -74,11 +80,13 @@ exp.save_hash = function(uuid, hash) {
// {hash: "0123456789abcdef", time: 1414881524512}
// null when uuid unkown
exp.get_details = function(uuid, callback) {
// get uuid in lower case if not null
uuid = uuid && uuid.toLowerCase();
redis.hgetall(uuid, function(err, data) {
var details = null;
if (data) {
details = {
hash: (data.h == "null" ? null : data.h),
hash: (data.h == "." ? null : data.h),
time: Number(data.t)
};
}

View File

@@ -112,10 +112,11 @@ exp.get_image_hash = function(uuid, callback) {
if (err) {
callback(err, -1, details && details.hash);
} else {
var oldhash = details && details.hash || "none";
logging.debug(uuid + " old hash: " + oldhash);
// skin is only checked (3) when uuid known AND hash didn't change
// in all other cases the skin is downloaded (2)
var status = details && (details.hash == hash) ? 3 : 2;
logging.debug(uuid + " old hash: " + (details && details.hash));
logging.log(uuid + " hash: " + hash);
var status = hash == oldhash ? 3 : 2;
callback(null, status, hash);
}
});