MCPcopy
hub / github.com/CopyTranslator/CopyTranslator / flush

Method flush

src/main/tracker.ts:65–83  ·  view source on GitHub ↗

* 手动或自动触发同步

()

Source from the content-addressed store, hash-verified

63 * 手动或自动触发同步
64 */
65 public async flush(): Promise<void> {
66 if (this.buffer.size === 0) return;
67
68 // 拷贝并清空缓冲区
69 const snapshot = Array.from(this.buffer.entries());
70 this.buffer.clear();
71
72 const events: AppEvent[] = snapshot.map(([compKey, count]) => {
73 const [type, key] = compKey.split('|');
74 return { type, key, version: this.version, count };
75 });
76
77 try {
78 await this.sendRequest({ events });
79 } catch (error) {
80 // 这里的错误可以静默处理,或者尝试将数据重新塞回 buffer
81 console.error('[Tracker] Sync failed:', error);
82 }
83 }
84
85 private sendRequest(payload: { events: AppEvent[] }): Promise<void> {
86 return axios

Callers 2

initMethod · 0.95
trackMethod · 0.95

Calls 2

sendRequestMethod · 0.95
clearMethod · 0.45

Tested by

no test coverage detected