• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mongodb-js / mongodb-mcp-server / 14672998392

25 Apr 2025 08:31PM UTC coverage: 82.446%. Remained the same
14672998392

Pull #137

github

nirinchev
Update name for fork workflow
Pull Request #137: chore: revamp gha workflows

135 of 212 branches covered (63.68%)

Branch coverage included in aggregate %.

748 of 859 relevant lines covered (87.08%)

48.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.29
/src/telemetry/eventCache.ts
1
import { BaseEvent } from "./types.js";
2
import { LRUCache } from "lru-cache";
31✔
3

4
/**
5
 * Singleton class for in-memory telemetry event caching
6
 * Provides a central storage for telemetry events that couldn't be sent
7
 * Uses LRU cache to automatically drop oldest events when limit is exceeded
8
 */
9
export class EventCache {
31✔
10
    private static instance: EventCache;
11
    private static readonly MAX_EVENTS = 1000;
31✔
12

13
    private cache: LRUCache<number, BaseEvent>;
14
    private nextId = 0;
26✔
15

16
    private constructor() {
17
        this.cache = new LRUCache({
26✔
18
            max: EventCache.MAX_EVENTS,
19
            // Using FIFO eviction strategy for events
20
            allowStale: false,
21
            updateAgeOnGet: false,
22
        });
23
    }
24

25
    /**
26
     * Gets the singleton instance of EventCache
27
     * @returns The EventCache instance
28
     */
29
    public static getInstance(): EventCache {
30
        if (!EventCache.instance) {
28✔
31
            EventCache.instance = new EventCache();
26✔
32
        }
33
        return EventCache.instance;
28✔
34
    }
35

36
    /**
37
     * Gets a copy of the currently cached events
38
     * @returns Array of cached BaseEvent objects
39
     */
40
    public getEvents(): BaseEvent[] {
41
        return Array.from(this.cache.values());
×
42
    }
43

44
    /**
45
     * Appends new events to the cached events
46
     * LRU cache automatically handles dropping oldest events when limit is exceeded
47
     * @param events - The events to append
48
     */
49
    public appendEvents(events: BaseEvent[]): void {
50
        for (const event of events) {
×
51
            this.cache.set(this.nextId++, event);
×
52
        }
53
    }
54

55
    /**
56
     * Clears all cached events
57
     */
58
    public clearEvents(): void {
59
        this.cache.clear();
×
60
        this.nextId = 0;
×
61
    }
62
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc