UNPKG

unleash-server

Version:

Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.

40 lines 1.43 kB
import { CRUDStore } from '../../db/crud/crud-store.js'; export class IntegrationEventsStore extends CRUDStore { constructor(db, config) { super('integration_events', db, config); } async getPaginatedEvents(id, limit, offset) { const endTimer = this.timer('getPaginatedEvents'); const rows = await this.db(this.tableName) .where('integration_id', id) .limit(limit) .offset(offset) .orderBy('id', 'desc'); endTimer(); return rows.map(this.fromRow); } async cleanUpEvents() { const endTimer = this.timer('cleanUpEvents'); await this.db .with('latest_events', (qb) => { qb.select('id') .from(this.tableName) .whereRaw(`created_at >= now() - INTERVAL '2 hours'`) .orderBy('id', 'desc') .limit(100); }) .with('latest_per_integration', (qb) => { qb.select(this.db.raw('MAX(id) as id')) .from(this.tableName) .groupBy('integration_id'); }) .from(this.tableName) .whereNotIn('id', this.db .select('id') .from('latest_events') .union(this.db.select('id').from('latest_per_integration'))) .delete(); endTimer(); } } //# sourceMappingURL=integration-events-store.js.map