always consider premium accounts to be active

pull/1/head
ansuz 4 years ago
parent 5358fab615
commit 6ada5fd751

@ -36,12 +36,27 @@ Quota.applyCustomLimits = function (Env) {
return limits;
}(Env.customLimits || {}));
Env.limits = Env.limits || {};
Object.keys(customLimits).forEach(function (k) {
if (!isLimit(customLimits[k])) { return; }
Env.limits[k] = customLimits[k];
});
};
/*
Env = {
myDomain,
mySubdomain,
adminEmail,
Package.version,
};
*/
Quota.queryAccountServer = function (Env, cb) {
cb = cb; // XXX
};
Quota.updateCachedLimits = function (Env, cb) {
Quota.applyCustomLimits(Env);
if (Env.blockDailyCheck === true ||
@ -80,6 +95,8 @@ Quota.updateCachedLimits = function (Env, cb) {
var json = JSON.parse(str);
Env.limits = json;
Quota.applyCustomLimits(Env);
//console.log('Env.customLimits', Env.customLimits);
//console.log('Env.limits', Env.limits);
cb(void 0);
} catch (e) {
cb(e);

@ -12,12 +12,17 @@ var getNewestTime = function (stats) {
/*
Env = {
limits: {
<unsafeKey>: <limit>,
},
config: {
inactiveTime: <number of days>,
archiveRetentionTime: <number of days>,
accountRetentionTime: <number of days>,
pinPath: <filesystem path>,
customLimits: <custom limits map>,
},
store,
pinStore,
@ -38,6 +43,17 @@ module.exports = function (Env, cb) {
return void complete("NO_INACTIVE_TIME");
}
// get a list of premium accounts on this instance
// pre-converted to the 'safeKey' format so we can easily compare
// them against ids we see on the filesystem
var premiumSafeKeys = Object.keys(Env.limits || {})
.filter(function (key) {
return key.length === 44;
})
.map(function (unsafeKey) {
return Util.escapeKeyCharacters(unsafeKey);
});
// files which have not been changed since before this date can be considered inactive
var inactiveTime = +new Date() - (config.inactiveTime * 24 * 3600 * 1000);
@ -276,17 +292,24 @@ module.exports = function (Env, cb) {
});
};
var accountIsActive = function (mtime, pinList) {
// XXX don't ever delete premium accounts...
var docIsActive = function (docId) {
return activeDocs.test(docId);
};
var accountIsActive = function (mtime, pinList, id) {
// console.log("id [%s] in premiumSafeKeys", id, premiumSafeKeys.indexOf(id) !== -1); // XXX
// if their pin log has changed recently then consider them active
if (mtime && mtime > accountRetentionTime) {
return true;
}
// otherwise iterate over their pinned documents until you find one that has been active
return pinList.some(function (docId) {
return activeDocs.test(docId);
});
// iterate over their pinned documents until you find one that has been active
if (pinList.some(docIsActive)) {
return true;
}
// Finally, make sure it's not a premium account
return premiumSafeKeys.indexOf(id) !== -1;
};
var PRESERVE_INACTIVE_ACCOUNTS = accountRetentionTime <= 0;
@ -299,7 +322,7 @@ module.exports = function (Env, cb) {
var mtime = content.latest;
var pinList = Object.keys(content.pins);
if (accountIsActive(mtime, pinList)) {
if (accountIsActive(mtime, pinList, id)) {
// add active accounts' pinned documents to a second bloom filter
pinAll(pinList);
return void next();

@ -3,12 +3,18 @@ var nThen = require("nthen");
var Store = require("../lib/storage/file");
var BlobStore = require("../lib/storage/blob");
var Quota = require("../lib/commands/quota");
var Env = {
config: require("../lib/load-config"),
};
var prepareEnv = function (Env, cb) {
var config = Env.config;
Env.customLimits = config.customLimits;
Quota.applyCustomLimits(Env);
nThen(function (w) {
/* Database adaptors
*/
@ -55,9 +61,9 @@ var prepareEnv = function (Env, cb) {
var shutdown = function (Env) {
// the store will keep this script running if you don't shut it down
Env.store.shutdown();
Env.Log.shutdown();
Env.pinStore.shutdown();
//Env.store.shutdown();
//Env.Log.shutdown();
//Env.pinStore.shutdown();
};
nThen(function (w) {

Loading…
Cancel
Save