unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
27 lines • 1.37 kB
JavaScript
import metricsHelper from '../../util/metrics-helper.js';
import { DB_TIME } from '../../metric-events.js';
const TABLE = 'users';
export class InactiveUsersStore {
constructor(db, eventBus, _getLogger) {
this.db = db;
this.timer = (action) => metricsHelper.wrapTimer(eventBus, DB_TIME, {
store: 'inactive_users',
action,
});
}
async getInactiveUsers(daysInactive) {
const stopTimer = this.timer('get_inactive_users');
const inactiveUsers = await this.db(TABLE)
.select('users.id AS id', 'users.name AS name', 'users.username AS username', 'users.email AS email', 'users.seen_at AS seen_at', 'pat.seen_at AS pat_seen_at', 'users.created_at AS created_at')
.leftJoin('personal_access_tokens AS pat', 'pat.user_id', 'users.id')
.where('deleted_at', null)
.andWhere('is_service', false)
.andWhere('is_system', false)
.andWhereRaw(`(users.seen_at IS NULL OR users.seen_at < now() - INTERVAL '?? days')
AND (users.created_at IS NULL OR users.created_at < now() - INTERVAL '?? days')
AND (pat.seen_at IS NULL OR pat.seen_at < now() - INTERVAL '?? days')`, [daysInactive, daysInactive, daysInactive]);
stopTimer();
return inactiveUsers;
}
}
//# sourceMappingURL=inactive-users-store.js.map