mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-21 23:41:18 +01:00
use EPHEMERAL_STORAGE instead of HEROKU env
afaik you can have persistent storage on heroku, at least via addons and heroku is probably not the only environment where one has a temporary file system
This commit is contained in:
parent
ac9cd93c8e
commit
e56f300d3e
2
app.json
2
app.json
@ -10,7 +10,7 @@
|
|||||||
],
|
],
|
||||||
"website": "https://crafatar.com/",
|
"website": "https://crafatar.com/",
|
||||||
"env": {
|
"env": {
|
||||||
"HEROKU": "true",
|
"EPHEMERAL_STORAGE": "true",
|
||||||
"BUILDPACK_URL": "https://github.com/mojodna/heroku-buildpack-multi.git#build-env"
|
"BUILDPACK_URL": "https://github.com/mojodna/heroku-buildpack-multi.git#build-env"
|
||||||
},
|
},
|
||||||
"addons": [
|
"addons": [
|
||||||
|
|||||||
15
lib/cache.js
15
lib/cache.js
@ -8,11 +8,11 @@ var fs = require("fs");
|
|||||||
var redis = null;
|
var redis = null;
|
||||||
|
|
||||||
// sets up redis connection
|
// sets up redis connection
|
||||||
// flushes redis when running on heroku (files aren't kept between pushes)
|
// flushes redis when using ephemeral storage (e.g. Heroku)
|
||||||
function connect_redis() {
|
function connect_redis() {
|
||||||
logging.log("connecting to redis...");
|
logging.log("connecting to redis...");
|
||||||
// parse redis env
|
// parse redis env
|
||||||
var redis_env = (process.env.REDISCLOUD_URL || process.env.REDIS_URL);
|
var redis_env = process.env.REDISCLOUD_URL || process.env.REDIS_URL;
|
||||||
var redis_url = redis_env ? url.parse(redis_env) : {};
|
var redis_url = redis_env ? url.parse(redis_env) : {};
|
||||||
redis_url.port = redis_url.port || 6379;
|
redis_url.port = redis_url.port || 6379;
|
||||||
redis_url.hostname = redis_url.hostname || "localhost";
|
redis_url.hostname = redis_url.hostname || "localhost";
|
||||||
@ -23,8 +23,8 @@ function connect_redis() {
|
|||||||
}
|
}
|
||||||
redis.on("ready", function() {
|
redis.on("ready", function() {
|
||||||
logging.log("Redis connection established.");
|
logging.log("Redis connection established.");
|
||||||
if (process.env.HEROKU) {
|
if (process.env.EPHEMERAL_STORAGE) {
|
||||||
logging.log("Running on heroku, flushing redis");
|
logging.log("Storage is ephemeral, flushing redis");
|
||||||
redis.flushall();
|
redis.flushall();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -68,7 +68,6 @@ exp.get_redis = function() {
|
|||||||
// callback: error, info object
|
// callback: error, info object
|
||||||
exp.info = function(callback) {
|
exp.info = function(callback) {
|
||||||
redis.info(function(err, res) {
|
redis.info(function(err, res) {
|
||||||
|
|
||||||
// parse the info command and store it in redis.server_info
|
// parse the info command and store it in redis.server_info
|
||||||
|
|
||||||
// this code block was taken from mranney/node_redis#on_info_cmd
|
// this code block was taken from mranney/node_redis#on_info_cmd
|
||||||
@ -99,7 +98,7 @@ exp.info = function(callback) {
|
|||||||
// callback: error
|
// callback: error
|
||||||
exp.update_timestamp = function(rid, userId, hash, temp, callback) {
|
exp.update_timestamp = function(rid, userId, hash, 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;
|
||||||
// store userId in lower case if not null
|
// store userId in lower case if not null
|
||||||
userId = userId && userId.toLowerCase();
|
userId = userId && userId.toLowerCase();
|
||||||
@ -117,8 +116,8 @@ exp.save_hash = function(rid, userId, skin_hash, cape_hash, callback) {
|
|||||||
logging.debug(rid, "caching skin:" + skin_hash + " cape:" + cape_hash);
|
logging.debug(rid, "caching skin:" + skin_hash + " cape:" + cape_hash);
|
||||||
var time = Date.now();
|
var time = Date.now();
|
||||||
// store shorter null byte instead of "null"
|
// store shorter null byte instead of "null"
|
||||||
skin_hash = (skin_hash === null ? "" : skin_hash);
|
skin_hash = skin_hash === null ? "" : skin_hash;
|
||||||
cape_hash = (cape_hash === null ? "" : cape_hash);
|
cape_hash = cape_hash === null ? "" : cape_hash;
|
||||||
// store userId in lower case if not null
|
// store userId in lower case if not null
|
||||||
userId = userId && userId.toLowerCase();
|
userId = userId && userId.toLowerCase();
|
||||||
if (skin_hash === undefined) {
|
if (skin_hash === undefined) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user