From df0cfa66b5b837be1ac44962f2046831334cacee Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Mon, 15 Jul 2024 19:35:16 -0700 Subject: [PATCH 1/3] Handle AreAPICodeFilesTheSame for cases where the Parser Version is different --- src/dotnet/APIView/APIViewWeb/Managers/CodeFileManager.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/dotnet/APIView/APIViewWeb/Managers/CodeFileManager.cs b/src/dotnet/APIView/APIViewWeb/Managers/CodeFileManager.cs index e01d5704326..3efcea480c3 100644 --- a/src/dotnet/APIView/APIViewWeb/Managers/CodeFileManager.cs +++ b/src/dotnet/APIView/APIViewWeb/Managers/CodeFileManager.cs @@ -201,6 +201,11 @@ public async Task CreateReviewCodeFileModel(string apiRevision /// public async Task AreAPICodeFilesTheSame(RenderedCodeFile codeFileA, RenderedCodeFile codeFileB) { + if (codeFileA.CodeFile.VersionString != codeFileA.CodeFile.VersionString) + { + return false; + } + if (LanguageServiceHelpers.UseTreeStyleParser(codeFileA.CodeFile.Language)) { var diffTree =CodeFileHelpers.ComputeAPIForestDiff(codeFileA.CodeFile.APIForest, codeFileB.CodeFile.APIForest); From 2325c9dcd0ddcd07a220eeb275b3dfb65bebe150 Mon Sep 17 00:00:00 2001 From: Praveen Kuttappan Date: Tue, 16 Jul 2024 00:30:59 -0400 Subject: [PATCH 2/3] Deserialize code file using correct foramt --- .../Repositories/BlobCodeFileRepository.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/dotnet/APIView/APIViewWeb/Repositories/BlobCodeFileRepository.cs b/src/dotnet/APIView/APIViewWeb/Repositories/BlobCodeFileRepository.cs index b7be0d1a3ea..971bde6418f 100644 --- a/src/dotnet/APIView/APIViewWeb/Repositories/BlobCodeFileRepository.cs +++ b/src/dotnet/APIView/APIViewWeb/Repositories/BlobCodeFileRepository.cs @@ -45,7 +45,18 @@ public async Task GetCodeFileAsync(string revisionId, string c var info = await client.DownloadAsync(); - codeFile = new RenderedCodeFile(await CodeFile.DeserializeAsync(info.Value.Content, doTreeStyleParserDeserialization: LanguageServiceHelpers.UseTreeStyleParser(language))); + CodeFile deserializedCodeFile = null; + // Try to deserialize the code file twice, as the first time might fail due to the file being not yet updated to new tree token format. + // This is a temporary work around. We should have a property in Cosmos revision to indicate whether a token is using new format or old format. + try + { + deserializedCodeFile = await CodeFile.DeserializeAsync(info.Value.Content, doTreeStyleParserDeserialization: LanguageServiceHelpers.UseTreeStyleParser(language)); + } + catch + { + deserializedCodeFile = await CodeFile.DeserializeAsync(info.Value.Content, doTreeStyleParserDeserialization: false); + } + codeFile = new RenderedCodeFile(deserializedCodeFile); if (updateCache) { From 09b60b261fd0535d813f0ebdfbbe1c219b259ae2 Mon Sep 17 00:00:00 2001 From: Praveen Kuttappan Date: Tue, 16 Jul 2024 00:58:11 -0400 Subject: [PATCH 3/3] Sanitize token code file name --- src/dotnet/APIView/APIViewWeb/Languages/LanguageProcessor.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/dotnet/APIView/APIViewWeb/Languages/LanguageProcessor.cs b/src/dotnet/APIView/APIViewWeb/Languages/LanguageProcessor.cs index 531403b1827..72f08bee6a8 100644 --- a/src/dotnet/APIView/APIViewWeb/Languages/LanguageProcessor.cs +++ b/src/dotnet/APIView/APIViewWeb/Languages/LanguageProcessor.cs @@ -26,6 +26,9 @@ public override async Task GetCodeFileAsync(string originalName, Strea var tempDirectory = Path.Combine(tempPath, "ApiView", randomSegment); Directory.CreateDirectory(tempDirectory); originalName = Path.GetFileName(originalName); + // Replace spaces and parentheses in the file name to remove invalid file name in cosmos DB. + // temporary work around. We need to make sure FileName is set for all requests. + originalName = originalName.Replace(" ", "_").Replace("(", "").Replace(")",""); var originalFilePath = Path.Combine(tempDirectory, originalName); var jsonFilePath = (LanguageServiceHelpers.UseTreeStyleParser(this.Name)) ? Path.ChangeExtension(originalFilePath, ".json.tgz") : Path.ChangeExtension(originalFilePath, ".json");