|
|
@ -2,6 +2,7 @@ var nThen = require("nthen");
|
|
|
|
var Bloom = require("@mcrowe/minibloom");
|
|
|
|
var Bloom = require("@mcrowe/minibloom");
|
|
|
|
var Util = require("../lib/common-util");
|
|
|
|
var Util = require("../lib/common-util");
|
|
|
|
var Pins = require("../lib/pins");
|
|
|
|
var Pins = require("../lib/pins");
|
|
|
|
|
|
|
|
var Keys = require("./keys");
|
|
|
|
|
|
|
|
|
|
|
|
var getNewestTime = function (stats) {
|
|
|
|
var getNewestTime = function (stats) {
|
|
|
|
return stats[['atime', 'ctime', 'mtime'].reduce(function (a, b) {
|
|
|
|
return stats[['atime', 'ctime', 'mtime'].reduce(function (a, b) {
|
|
|
@ -42,12 +43,11 @@ module.exports = function (Env, cb) {
|
|
|
|
// pre-converted to the 'safeKey' format so we can easily compare
|
|
|
|
// pre-converted to the 'safeKey' format so we can easily compare
|
|
|
|
// them against ids we see on the filesystem
|
|
|
|
// them against ids we see on the filesystem
|
|
|
|
var premiumSafeKeys = Object.keys(Env.limits || {})
|
|
|
|
var premiumSafeKeys = Object.keys(Env.limits || {})
|
|
|
|
.filter(function (key) {
|
|
|
|
.map(function (id) {
|
|
|
|
return key.length === 44;
|
|
|
|
return Keys.canonicalize(id);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.map(function (unsafeKey) {
|
|
|
|
.filter(Boolean)
|
|
|
|
return Util.escapeKeyCharacters(unsafeKey);
|
|
|
|
.map(Util.escapeKeyCharacters);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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() - (Env.inactiveTime * 24 * 3600 * 1000);
|
|
|
|
var inactiveTime = +new Date() - (Env.inactiveTime * 24 * 3600 * 1000);
|
|
|
@ -291,7 +291,7 @@ module.exports = function (Env, cb) {
|
|
|
|
return activeDocs.test(docId);
|
|
|
|
return activeDocs.test(docId);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var accountIsActive = function (mtime, pinList, id) {
|
|
|
|
var accountIsActive = function (mtime, pinList) {
|
|
|
|
// console.log("id [%s] in premiumSafeKeys", id, premiumSafeKeys.indexOf(id) !== -1);
|
|
|
|
// console.log("id [%s] in premiumSafeKeys", id, premiumSafeKeys.indexOf(id) !== -1);
|
|
|
|
// 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) {
|
|
|
@ -299,11 +299,10 @@ module.exports = function (Env, cb) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// iterate over their pinned documents until you find one that has been active
|
|
|
|
// iterate over their pinned documents until you find one that has been active
|
|
|
|
if (pinList.some(docIsActive)) {
|
|
|
|
return pinList.some(docIsActive);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Finally, make sure it's not a premium account
|
|
|
|
var isPremiumAccount = function (id) {
|
|
|
|
return premiumSafeKeys.indexOf(id) !== -1;
|
|
|
|
return premiumSafeKeys.indexOf(id) !== -1;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -317,7 +316,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, id)) {
|
|
|
|
if (accountIsActive(mtime, pinList)) {
|
|
|
|
// 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();
|
|
|
@ -332,6 +331,15 @@ module.exports = function (Env, cb) {
|
|
|
|
return void next();
|
|
|
|
return void next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isPremiumAccount(id)) {
|
|
|
|
|
|
|
|
Log.info("EVICT_INACTIVE_PREMIUM_ACCOUNT", {
|
|
|
|
|
|
|
|
id: id,
|
|
|
|
|
|
|
|
mtime: mtime,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
pinAll(pinList);
|
|
|
|
|
|
|
|
return void next();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// remove the pin logs of inactive accounts if inactive account removal is configured
|
|
|
|
// remove the pin logs of inactive accounts if inactive account removal is configured
|
|
|
|
pinStore.archiveChannel(id, function (err) {
|
|
|
|
pinStore.archiveChannel(id, function (err) {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
@ -348,6 +356,9 @@ module.exports = function (Env, cb) {
|
|
|
|
"EVICT_COUNT_ACCOUNTS":
|
|
|
|
"EVICT_COUNT_ACCOUNTS":
|
|
|
|
"EVICT_INACTIVE_ACCOUNTS";
|
|
|
|
"EVICT_INACTIVE_ACCOUNTS";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// update the number of known active accounts in Env for statistics
|
|
|
|
|
|
|
|
Env.knownActiveAccounts = accounts - inactive;
|
|
|
|
|
|
|
|
|
|
|
|
Log.info(label, {
|
|
|
|
Log.info(label, {
|
|
|
|
accounts: accounts,
|
|
|
|
accounts: accounts,
|
|
|
|
inactive: inactive,
|
|
|
|
inactive: inactive,
|
|
|
|