|
|
|
@ -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();
|
|
|
|
|