Skip to content

Commit

Permalink
Avoid code file caching when for new tree style code files (#8874)
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenkuttappan authored Aug 23, 2024
1 parent 5590e2b commit a371747
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ public async Task<ActionResult<CodePanelData>> GetReviewContentAsync(string revi
if (activeAPIRevision.Files[0].ParserStyle == ParserStyle.Tree)
{
var comments = await _commentsManager.GetCommentsAsync(reviewId);
var cachedCodeFile = await _codeFileRepository.GetCodeFileAsync(revisionId: activeAPIRevision.Id, codeFileId: activeAPIRevision.Files[0].FileId);
var activeRevisionReviewCodeFile = cachedCodeFile.CodeFile;
var activeRevisionReviewCodeFile = await _codeFileRepository.GetCodeFileFromStorageAsync(revisionId: activeAPIRevision.Id, codeFileId: activeAPIRevision.Files[0].FileId);

var codePanelRawData = new CodePanelRawData()
{
Expand All @@ -149,8 +148,7 @@ public async Task<ActionResult<CodePanelData>> GetReviewContentAsync(string revi
if (!string.IsNullOrEmpty(diffApiRevisionId))
{
var diffAPIRevision = await _apiRevisionsManager.GetAPIRevisionAsync(User, diffApiRevisionId);
var diffCodeFile = await _codeFileRepository.GetCodeFileAsync(revisionId: diffAPIRevision.Id, codeFileId: diffAPIRevision.Files[0].FileId);
codePanelRawData.diffRevisionCodeFile = diffCodeFile.CodeFile;
codePanelRawData.diffRevisionCodeFile = await _codeFileRepository.GetCodeFileFromStorageAsync(revisionId: diffAPIRevision.Id, codeFileId: diffAPIRevision.Files[0].FileId);
}

// Render the code files to generate UI token tree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,15 @@ public Task<RenderedCodeFile> GetCodeFileAsync(APIRevisionListItemModel revision

public async Task<RenderedCodeFile> GetCodeFileAsync(string revisionId, APICodeFileModel apiCodeFile, string language, bool updateCache = true)
{
return await GetCodeFileAsync(revisionId, apiCodeFile.FileId, updateCache, apiCodeFile.ParserStyle == ParserStyle.Tree);
}

public async Task<RenderedCodeFile> GetCodeFileAsync(string revisionId, string codeFileId, bool updateCache = true, bool doTreeStyleParserDeserialization = true)
{
var client = GetBlobClient(revisionId, codeFileId, out var key);
var client = GetBlobClient(revisionId, apiCodeFile.FileId, out var key);
if (_cache.TryGetValue<RenderedCodeFile>(key, out var codeFile))
{
return codeFile;
}

var info = await client.DownloadAsync();

codeFile = new RenderedCodeFile(await CodeFile.DeserializeAsync(info.Value.Content, doTreeStyleParserDeserialization));
codeFile = new RenderedCodeFile(await CodeFile.DeserializeAsync(info.Value.Content, false));

if (updateCache)
{
Expand All @@ -58,6 +53,14 @@ public async Task<RenderedCodeFile> GetCodeFileAsync(string revisionId, string c
.SetValue(codeFile);
}
return codeFile;
}

public async Task<CodeFile> GetCodeFileFromStorageAsync(string revisionId, string codeFileId, bool doTreeStyleParserDeserialization = true)
{
var client = GetBlobClient(revisionId, codeFileId, out var key);
var info = await client.DownloadAsync();
var codeFile = await CodeFile.DeserializeAsync(info.Value.Content, doTreeStyleParserDeserialization);
return codeFile;
}

public async Task UpsertCodeFileAsync(string revisionId, string codeFileId, CodeFile codeFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public interface IBlobCodeFileRepository
{
public Task<RenderedCodeFile> GetCodeFileAsync(APIRevisionListItemModel revision, bool updateCache = true);
public Task<RenderedCodeFile> GetCodeFileAsync(string revisionId, APICodeFileModel apiCodeFile, string language, bool updateCache = true);
public Task<RenderedCodeFile> GetCodeFileAsync(string revisionId, string codeFileId, bool updateCache = true, bool doTreeStyleParserDeserialization = true);
public Task UpsertCodeFileAsync(string revisionId, string codeFileId, CodeFile codeFile);
public Task DeleteCodeFileAsync(string revisionId, string codeFileId);
public Task<CodeFile> GetCodeFileFromStorageAsync(string revisionId, string codeFileId, bool doTreeStyleParserDeserialization = true);
}
}

0 comments on commit a371747

Please sign in to comment.