MCPcopy Create free account
hub / github.com/echoVic/blade-code / getStorageStats

Method getStorageStats

src/context/storage/PersistentStore.ts:198–262  ·  view source on GitHub ↗

* 获取存储统计信息

()

Source from the content-addressed store, hash-verified

196 * 获取存储统计信息
197 */
198 async getStorageStats(): Promise<{
199 totalSessions: number;
200 totalSize: number; // 字节
201 oldestSession: string | null;
202 newestSession: string | null;
203 }> {
204 try {
205 const sessions = await this.listSessions();
206
207 if (sessions.length === 0) {
208 return {
209 totalSessions: 0,
210 totalSize: 0,
211 oldestSession: null,
212 newestSession: null,
213 };
214 }
215
216 // 计算总大小
217 let totalSize = 0;
218 for (const sessionId of sessions) {
219 try {
220 const sessionPath = path.join(this.storagePath, 'sessions', `${sessionId}.json`);
221 const conversationPath = path.join(
222 this.storagePath,
223 'conversations',
224 `${sessionId}.json`
225 );
226
227 const [sessionStat, conversationStat] = await Promise.all([
228 fs.stat(sessionPath).catch(() => ({ size: 0 })),
229 fs.stat(conversationPath).catch(() => ({ size: 0 })),
230 ]);
231
232 totalSize += sessionStat.size + conversationStat.size;
233 } catch (error) {
234 // 忽略单个文件的错误
235 }
236 }
237
238 // 获取最新和最旧的会话
239 const sessionSummaries = await Promise.all(
240 sessions.map(sessionId => this.getSessionSummary(sessionId))
241 );
242
243 const validSummaries = sessionSummaries
244 .filter((summary): summary is NonNullable<typeof summary> => summary !== null)
245 .sort((a, b) => a.lastActivity - b.lastActivity);
246
247 return {
248 totalSessions: sessions.length,
249 totalSize,
250 oldestSession: validSummaries[0]?.sessionId || null,
251 newestSession: validSummaries[validSummaries.length - 1]?.sessionId || null,
252 };
253 } catch (error) {
254 console.warn('警告:获取存储统计信息时出错:', error);
255 return {

Callers 1

getStatsMethod · 0.80

Calls 4

listSessionsMethod · 0.95
getSessionSummaryMethod · 0.95
filterMethod · 0.45
warnMethod · 0.45

Tested by

no test coverage detected