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