Skip to content

Commit

Permalink
feat: 2x preprocess speed
Browse files Browse the repository at this point in the history
  • Loading branch information
8bitgentleman committed Oct 20, 2023
1 parent b0c5b54 commit 1e64a43
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions roam/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,9 @@ function resolveBlockRef(blockLocations: Map<string, BlockInfo>, sourceBlockUID:
return strippedSourceBlockString
}

function preprocess(pages: RoamPage[]): [Map<string, BlockInfo>, Map<string, BlockInfo>] {
function preprocess(pages: RoamPage[]): Map<string, BlockInfo> {
// preprocess/map the graph so each block can be quickly found
const blockLocations: Map<string, BlockInfo> = new Map();
const toPostProcessblockLocations: Map<string, BlockInfo> = new Map();

function processBlock(page: RoamPage, block: RoamBlock) {
if (block[':block/uid']) {
Expand All @@ -186,10 +185,6 @@ function preprocess(pages: RoamPage[]): [Map<string, BlockInfo>, Map<string, Blo
blockString: block[':block/string'] || '', // Ensure block.string is defined
};

const blockRefRegex = /.*?(\(\(.*?\)\)).*?/g;
if (blockRefRegex.test(info.blockString)) {
toPostProcessblockLocations.set(block[':block/uid'], info);
}
blockLocations.set(block[':block/uid'], info);
}

Expand All @@ -208,7 +203,7 @@ function preprocess(pages: RoamPage[]): [Map<string, BlockInfo>, Map<string, Blo
}
}

return [blockLocations, toPostProcessblockLocations];
return blockLocations;
}

function findPagesByTitles(pages: RoamPage[], titlesToFind: String[]): RoamPage[] {
Expand Down Expand Up @@ -256,7 +251,7 @@ const main = async (pages:String[]) => {
console.log("~~pages downloaded");
console.log("~~~~starting block preprocess");
// PRE-PROCESS: map the blocks for easy lookup //
const [blockLocations, toPostProcess] = preprocess(allPages);
const blockLocations = preprocess(allPages);
console.log("~~block preprocess finished");

const filteredPages = findPagesByTitles(allPages, pages)
Expand Down

0 comments on commit 1e64a43

Please sign in to comment.