File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,6 +35,12 @@ const remoteFileContentCache = new LRU<string, string>({
3535 sizeCalculation : ( value ) => value . length ,
3636} ) ;
3737
38+ const gitDiffCache = new LRU < string , string > ( {
39+ max : 500 ,
40+ maxSize : 10485760 ,
41+ sizeCalculation : ( value ) => value . length ,
42+ } ) ;
43+
3844const EMPTY_BLOB_SHA = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" ;
3945
4046export const patchedFilenameRegex =
@@ -902,6 +908,12 @@ export async function gitDiffBlobs(
902908 blobIdA : string ,
903909 blobIdB : string ,
904910) {
911+ const cacheKey = `${ filename } :${ blobIdA } ..${ blobIdB } ` ;
912+
913+ if ( gitDiffCache . has ( cacheKey ) ) {
914+ return gitDiffCache . get ( cacheKey ) ! ;
915+ }
916+
905917 if ( ! / ^ [ 0 - 9 a - f ] + $ / . test ( blobIdA ) ) {
906918 throw new Error ( `Invalid blob ID: ${ blobIdA } ` ) ;
907919 }
@@ -933,10 +945,12 @@ export async function gitDiffBlobs(
933945 `new file mode 100644\nindex ${ blobIdA } ..${ blobIdB } ` ,
934946 ) ;
935947
948+ gitDiffCache . set ( cacheKey , fileDiff ) ;
936949 return fileDiff ;
937950 }
938951
939952 const stdout = await gitDiffBlobsInternal ( cwd , filename , blobIdA , blobIdB ) ;
953+ gitDiffCache . set ( cacheKey , stdout ) ;
940954
941955 return stdout ;
942956}
You can’t perform that action at this time.
0 commit comments