MCPcopy Create free account
hub / github.com/CatMuse/HiNote / checkOrphanedDataCount

Method checkOrphanedDataCount

src/services/HighlightManager.ts:160–199  ·  view source on GitHub ↗

* 检查孤立数据数量 * 检查所有存储的高亮和评论,统计那些在文档中找不到对应高亮文本的孤立数据数量 * @returns 孤立数据数量

()

Source from the content-addressed store, hash-verified

158 * @returns 孤立数据数量
159 */
160 async checkOrphanedDataCount(): Promise<{ orphanedHighlights: number; affectedFiles: number }> {
161 let orphanedHighlights = 0;
162 let affectedFiles = new Set<string>();
163
164 const allHighlights = this.repository.getAllCachedHighlights();
165
166 for (const [filePath, highlights] of allHighlights.entries()) {
167 const file = this.app.vault.getAbstractFileByPath(filePath);
168 if (!file || !(file instanceof TFile)) {
169 affectedFiles.add(filePath);
170 orphanedHighlights += highlights.length;
171 continue;
172 }
173
174 try {
175 const content = await this.app.vault.read(file);
176 const extractedHighlights = this.highlightService.extractHighlights(content, file);
177 const extractedTexts = new Set(extractedHighlights.map(h => h.text));
178
179 let fileHasOrphans = false;
180
181 for (const highlight of highlights) {
182 if (highlight.isVirtual) continue;
183
184 if (!extractedTexts.has(highlight.text)) {
185 orphanedHighlights++;
186 fileHasOrphans = true;
187 }
188 }
189
190 if (fileHasOrphans) {
191 affectedFiles.add(filePath);
192 }
193 } catch {
194 // 错误处理
195 }
196 }
197
198 return { orphanedHighlights, affectedFiles: affectedFiles.size };
199 }
200
201 /**
202 * 清理孤立数据

Callers 2

displayMethod · 0.80

Calls 2

extractHighlightsMethod · 0.45

Tested by

no test coverage detected