|
|
@ -273,7 +273,6 @@ var categorizeAccountsByActivity = function (w) {
|
|
|
|
var inactive = 0;
|
|
|
|
var inactive = 0;
|
|
|
|
|
|
|
|
|
|
|
|
var accountRetentionTime;
|
|
|
|
var accountRetentionTime;
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof(config.accountRetentionTime) === 'number' && config.accountRetentionTime > 0) {
|
|
|
|
if (typeof(config.accountRetentionTime) === 'number' && config.accountRetentionTime > 0) {
|
|
|
|
accountRetentionTime = +new Date() - (24 * 3600 * 1000 * config.accountRetentionTime);
|
|
|
|
accountRetentionTime = +new Date() - (24 * 3600 * 1000 * config.accountRetentionTime);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -286,44 +285,44 @@ var categorizeAccountsByActivity = function (w) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var handler;
|
|
|
|
var accountIsActive = function (mtime, pinList) {
|
|
|
|
|
|
|
|
// if their pin log has changed recently then consider them active
|
|
|
|
if (accountRetentionTime < 0) {
|
|
|
|
if (mtime && mtime > accountRetentionTime) {
|
|
|
|
// this means we'll retain all accounts
|
|
|
|
return true;
|
|
|
|
// so the pin log handler can be very simple
|
|
|
|
}
|
|
|
|
handler = function (content, id, next) {
|
|
|
|
// otherwise iterate over their pinned documents until you find one that has been active
|
|
|
|
pinAll(Object.keys(content.pins));
|
|
|
|
return pinList.some(function (docId) {
|
|
|
|
next();
|
|
|
|
return activeDocs.test(docId);
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
var PRESERVE_INACTIVE_ACCOUNTS = accountRetentionTime <= 0;
|
|
|
|
|
|
|
|
|
|
|
|
// otherwise, we'll only retain data from active accounts
|
|
|
|
// otherwise, we'll only retain data from active accounts
|
|
|
|
// so we need more heuristics
|
|
|
|
// so we need more heuristics
|
|
|
|
handler = function (content, id, next) {
|
|
|
|
var handler = function (content, id, next) {
|
|
|
|
accounts++;
|
|
|
|
accounts++;
|
|
|
|
//console.log(content, id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var mtime = content.latest;
|
|
|
|
var mtime = content.latest;
|
|
|
|
|
|
|
|
|
|
|
|
var pinList = Object.keys(content.pins);
|
|
|
|
var pinList = Object.keys(content.pins);
|
|
|
|
// if their pin log has changed recently then consider them active
|
|
|
|
|
|
|
|
if (mtime && mtime > accountRetentionTime) {
|
|
|
|
if (accountIsActive(mtime, pinList)) {
|
|
|
|
// the account is active
|
|
|
|
// add active accounts' pinned documents to a second bloom filter
|
|
|
|
pinAll(pinList);
|
|
|
|
pinAll(pinList);
|
|
|
|
return void next();
|
|
|
|
return void next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// otherwise iterate over their pinned documents until you find one that has been active
|
|
|
|
// Otherwise they are inactive.
|
|
|
|
if (Object.keys(content.pins).some(function (docId) {
|
|
|
|
// We keep track of how many accounts are inactive whether or not
|
|
|
|
return !activeDocs.test(docId);
|
|
|
|
// we plan to delete them, because it may be interesting information
|
|
|
|
})) {
|
|
|
|
inactive++;
|
|
|
|
// add active accounts' pinned documents to a second bloom filter
|
|
|
|
if (PRESERVE_INACTIVE_ACCOUNTS) {
|
|
|
|
pinAll(pinList);
|
|
|
|
pinAll(pinList);
|
|
|
|
return void next();
|
|
|
|
return void next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if none are active then archive the pin log
|
|
|
|
// remove the pin logs of inactive accounts if inactive account removal is configured
|
|
|
|
pinStore.archiveChannel(id, function (err) {
|
|
|
|
pinStore.archiveChannel(id, function (err) {
|
|
|
|
console.log(inactive++);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|
Log.error('EVICT_INACTIVE_ACCOUNT_PIN_LOG', err);
|
|
|
|
Log.error('EVICT_INACTIVE_ACCOUNT_PIN_LOG', err);
|
|
|
|
return void next();
|
|
|
|
return void next();
|
|
|
@ -332,10 +331,13 @@ var categorizeAccountsByActivity = function (w) {
|
|
|
|
next();
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var done = function () {
|
|
|
|
var done = function () {
|
|
|
|
Log.info('EVICT_INACTIVE_ACCOUNTS', {
|
|
|
|
var label = PRESERVE_INACTIVE_ACCOUNTS?
|
|
|
|
|
|
|
|
"EVICT_COUNT_ACCOUNTS":
|
|
|
|
|
|
|
|
"EVICT_INACTIVE_ACCOUNTS";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.info(label, {
|
|
|
|
accounts: accounts,
|
|
|
|
accounts: accounts,
|
|
|
|
inactive: inactive,
|
|
|
|
inactive: inactive,
|
|
|
|
});
|
|
|
|
});
|
|
|
|