MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / sync

Function sync

src/sidebarApps/searchInFiles/indexWorker.js:81–154  ·  view source on GitHub ↗
(files)

Source from the content-addressed store, hash-verified

79}
80
81async function sync(files) {
82 const db = await getDB();
83 const existingRecords = await getExistingRecords(db);
84 let indexed = 0;
85 let skipped = 0;
86 const total = files.length;
87
88 postStatus({
89 state: total ? "indexing" : "ready",
90 indexed,
91 total,
92 message: total ? "Preparing search cache" : "Search cache ready",
93 });
94
95 for (const file of files) {
96 const currentRecord = existingRecords.get(file.url);
97
98 if (
99 currentRecord &&
100 !dirtyUrls.has(file.url) &&
101 isRecordCurrent(file, currentRecord)
102 ) {
103 indexed += 1;
104 if (currentRecord.skipped) skipped += 1;
105 continue;
106 }
107
108 try {
109 if (file.size && file.size > MAX_INDEXED_CHARS) {
110 const record = buildSkippedRecord(file, "large");
111 await writeRecord(db, currentRecord, record);
112 dirtyUrls.delete(file.url);
113 indexed += 1;
114 skipped += 1;
115 await yieldToEventLoop(INDEX_IDLE_DELAY);
116 continue;
117 }
118
119 const content = await getFile(file.url);
120 const record = buildRecord(file, content);
121 await writeRecord(db, currentRecord, record);
122 dirtyUrls.delete(file.url);
123 indexed += 1;
124 if (record.skipped) skipped += 1;
125 await yieldToEventLoop(INDEX_IDLE_DELAY);
126 } catch {
127 skipped += 1;
128 }
129
130 if (indexed % 25 === 0 || indexed === total) {
131 postStatus({
132 state: "indexing",
133 indexed,
134 total,
135 skipped,
136 message: `Cached ${indexed}/${total} files`,
137 });
138 await yieldToEventLoop();

Callers 1

runQueuedSyncFunction · 0.70

Calls 12

getDBFunction · 0.85
getExistingRecordsFunction · 0.85
postStatusFunction · 0.85
isRecordCurrentFunction · 0.85
buildSkippedRecordFunction · 0.85
writeRecordFunction · 0.85
yieldToEventLoopFunction · 0.85
buildRecordFunction · 0.85
deleteRecordFunction · 0.85
getFileFunction · 0.70
deleteMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected