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

mongodb-js / mongodb-mcp-server / 17497369294

05 Sep 2025 03:21PM UTC coverage: 81.286% (-0.07%) from 81.353%
17497369294

Pull #521

github

web-flow
Merge 544cd62ab into 14176badb
Pull Request #521: fix: don't wait for telemetry events MCP-179

956 of 1271 branches covered (75.22%)

Branch coverage included in aggregate %.

72 of 91 new or added lines in 6 files covered. (79.12%)

1 existing line in 1 file now uncovered.

4769 of 5772 relevant lines covered (82.62%)

45.27 hits per line

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

82.61
/src/telemetry/eventCache.ts
1
import { LRUCache } from "lru-cache";
2✔
2
import type { BaseEvent } from "./types.js";
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 {
2✔
10
    private static instance: EventCache;
11
    private static readonly MAX_EVENTS = 1000;
46✔
12

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

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

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

36
    /**
37
     * Gets the number of currently cached events
38
     */
39
    public get size(): number {
46✔
40
        return this.cache.size;
61✔
41
    }
61✔
42

43
    /**
44
     * Gets a copy of the currently cached events along with their ids
45
     * @returns Array of cached BaseEvent objects
46
     */
47
    public getEvents(): { id: number; event: BaseEvent }[] {
46✔
48
        return Array.from(this.cache.entries()).map(([id, event]) => ({ id, event }));
65✔
49
    }
65✔
50

51
    /**
52
     * Appends new events to the cached events
53
     * LRU cache automatically handles dropping oldest events when limit is exceeded
54
     * @param events - The events to append
55
     */
56
    public appendEvents(events: BaseEvent[]): void {
46✔
57
        for (const event of events) {
×
58
            this.cache.set(this.nextId++, event);
×
59
        }
×
60
    }
×
61

62
    /**
63
     * Removes cached events by their ids
64
     */
65
    public removeEvents(ids: number[]): void {
46✔
66
        for (const id of ids) {
65!
NEW
67
            this.cache.delete(id);
×
NEW
68
        }
×
69
    }
65✔
70
}
46✔
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