MCPcopy Index your code
hub / github.com/5e-bits/5e-database / _handleFileModified

Function _handleFileModified

scripts/update/processor.ts:241–260  ·  view source on GitHub ↗

* Handles processing for a modified file. * Calculates diff and applies updates/deletes to the existing collection.

(db: Db, filepath: string)

Source from the content-addressed store, hash-verified

239 * Calculates diff and applies updates/deletes to the existing collection.
240 */
241async function _handleFileModified(db: Db, filepath: string): Promise<void> {
242 const collectionName = getCollectionNameFromJsonFile(filepath);
243 if (!collectionName) {
244 console.warn(`Could not determine collection name for modified file ${filepath}. Skipping.`);
245 return;
246 }
247 console.log(`\nProcessing Modified file ${filepath} for collection '${collectionName}'...`);
248
249 const currentData = await readFileContent(filepath);
250 const oldFileContentString = await getOldFileContent(filepath);
251 const oldData = parseJsonArrayContent(oldFileContentString, `HEAD~1:${filepath}`);
252
253 const { operations, skippedRecords } = calculateBulkOperations(oldData, currentData, filepath);
254 await executeBulkWrite(db, collectionName, operations);
255
256 if (skippedRecords > 0) {
257 console.warn(`Skipped ${skippedRecords} records in ${filepath} due to missing 'index' field.`);
258 }
259 // No index update needed for modification
260}
261
262/**
263 * Handles processing for a renamed file.

Callers 1

processFileUpdateFunction · 0.85

Calls 6

getOldFileContentFunction · 0.90
readFileContentFunction · 0.85
parseJsonArrayContentFunction · 0.85
calculateBulkOperationsFunction · 0.85
executeBulkWriteFunction · 0.85

Tested by

no test coverage detected