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; return limits;
}(Env.customLimits || {})); }(Env.customLimits || {}));
Env.limits = Env.limits || {};
Object.keys(customLimits).forEach(function (k) { Object.keys(customLimits).forEach(function (k) {
if (!isLimit(customLimits[k])) { return; } if (!isLimit(customLimits[k])) { return; }
Env.limits[k] = customLimits[k]; 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.updateCachedLimits = function (Env, cb) {
Quota.applyCustomLimits(Env); Quota.applyCustomLimits(Env);
if (Env.blockDailyCheck === true || if (Env.blockDailyCheck === true ||
@ -80,6 +95,8 @@ Quota.updateCachedLimits = function (Env, cb) {
var json = JSON.parse(str); var json = JSON.parse(str);
Env.limits = json; Env.limits = json;
Quota.applyCustomLimits(Env); Quota.applyCustomLimits(Env);
//console.log('Env.customLimits', Env.customLimits);
//console.log('Env.limits', Env.limits);
cb(void 0); cb(void 0);
} catch (e) { } catch (e) {
cb(e); cb(e);

@ -12,12 +12,17 @@ var getNewestTime = function (stats) {
/* /*
Env = { Env = {
limits: {
<unsafeKey>: <limit>,
},
config: { config: {
inactiveTime: <number of days>, inactiveTime: <number of days>,
archiveRetentionTime: <number of days>, archiveRetentionTime: <number of days>,
accountRetentionTime: <number of days>, accountRetentionTime: <number of days>,
pinPath: <filesystem path>, pinPath: <filesystem path>,
customLimits: <custom limits map>,
}, },
store, store,
pinStore, pinStore,
@ -38,6 +43,17 @@ module.exports = function (Env, cb) {
return void complete("NO_INACTIVE_TIME"); 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 // files which have not been changed since before this date can be considered inactive
var inactiveTime = +new Date() - (config.inactiveTime * 24 * 3600 * 1000); var inactiveTime = +new Date() - (config.inactiveTime * 24 * 3600 * 1000);
@ -276,17 +292,24 @@ module.exports = function (Env, cb) {
}); });
}; };
var accountIsActive = function (mtime, pinList) { var docIsActive = function (docId) {
// XXX don't ever delete premium accounts... 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 their pin log has changed recently then consider them active
if (mtime && mtime > accountRetentionTime) { if (mtime && mtime > accountRetentionTime) {
return true; return true;
} }
// otherwise iterate over their pinned documents until you find one that has been active
return pinList.some(function (docId) { // iterate over their pinned documents until you find one that has been active
return activeDocs.test(docId); 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; var PRESERVE_INACTIVE_ACCOUNTS = accountRetentionTime <= 0;
@ -299,7 +322,7 @@ module.exports = function (Env, cb) {
var mtime = content.latest; var mtime = content.latest;
var pinList = Object.keys(content.pins); 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 // add active accounts' pinned documents to a second bloom filter
pinAll(pinList); pinAll(pinList);
return void next(); return void next();

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

Loading…
Cancel
Save