Skip to content

Commit

Permalink
Skip caching reviews access by backend services (#2131)
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenkuttappan authored Oct 21, 2021
1 parent 1e33dee commit 7caad50
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public BlobCodeFileRepository(IConfiguration configuration, IMemoryCache cache)
}


public Task<RenderedCodeFile> GetCodeFileAsync(ReviewRevisionModel revision)
public Task<RenderedCodeFile> GetCodeFileAsync(ReviewRevisionModel revision, bool updateCache = true)
{
return GetCodeFileAsync(revision.RevisionId, revision.SingleFile.ReviewFileId);
return GetCodeFileAsync(revision.RevisionId, revision.SingleFile.ReviewFileId, updateCache);
}

public async Task<RenderedCodeFile> GetCodeFileAsync(string revisionId, string codeFileId)
public async Task<RenderedCodeFile> GetCodeFileAsync(string revisionId, string codeFileId, bool updateCache = true)
{
var client = GetBlobClient(revisionId, codeFileId, out var key);

Expand All @@ -42,9 +42,12 @@ public async Task<RenderedCodeFile> GetCodeFileAsync(string revisionId, string c
var info = await client.DownloadAsync();
codeFile = new RenderedCodeFile(await CodeFile.DeserializeAsync(info.Value.Content));

using var _ = _cache.CreateEntry(key)
.SetSlidingExpiration(TimeSpan.FromDays(1))
.SetValue(codeFile);
if (updateCache)
{
using var _ = _cache.CreateEntry(key)
.SetSlidingExpiration(TimeSpan.FromHours(2))
.SetValue(codeFile);
}

return codeFile;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public async Task<string> GetApiDiffFromAutomaticReview(CodeFile codeFile, int p

private async Task GetFormattedDiff(RenderedCodeFile renderedCodeFile, ReviewRevisionModel lastRevision, StringBuilder stringBuilder)
{
RenderedCodeFile autoReview = await _codeFileRepository.GetCodeFileAsync(lastRevision);
RenderedCodeFile autoReview = await _codeFileRepository.GetCodeFileAsync(lastRevision, false);
var autoReviewTextFile = autoReview.RenderText(showDocumentation: false, skipDiff: true);
var prCodeTextFile = renderedCodeFile.RenderText(showDocumentation: false, skipDiff: true);
var diffLines = InlineDiff.Compute(autoReviewTextFile, prCodeTextFile, autoReviewTextFile, prCodeTextFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ private bool IsUpdateAvailable(ReviewModel review)
public async Task<bool> IsReviewSame(ReviewRevisionModel revision, RenderedCodeFile renderedCodeFile)
{
//This will compare and check if new code file content is same as revision in parameter
var lastRevisionFile = await _codeFileRepository.GetCodeFileAsync(revision);
var lastRevisionFile = await _codeFileRepository.GetCodeFileAsync(revision, false);
var lastRevisionTextLines = lastRevisionFile.RenderText(showDocumentation: false, skipDiff: true);
var fileTextLines = renderedCodeFile.RenderText(showDocumentation: false, skipDiff: true);
return lastRevisionTextLines.SequenceEqual(fileTextLines);
Expand Down

0 comments on commit 7caad50

Please sign in to comment.