Skip to content

Commit

Permalink
Fetch only review requested API reviews for logged in user (#4449)
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenkuttappan authored Oct 18, 2022
1 parent a103749 commit 798f598
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -27,10 +27,10 @@ public RequestedReviews(ReviewManager manager, UserPreferenceCache cache)

public async Task<IActionResult> OnGetAsync()
{
var fullResult = (await _manager.GetReviewsAsync(false, "All")).Where(r => r.RequestedReviewers != null).Where(r => r.RequestedReviewers.Contains(User.GetGitHubLogin()));
ActiveReviews = fullResult.Where(r => r.IsApproved == false).OrderByDescending(r => r.ApprovalRequestedOn);
var requestedReviews = await _manager.GetRequestedReviews(User.GetGitHubLogin());
ActiveReviews = requestedReviews.Where(r => r.IsApproved == false).OrderByDescending(r => r.ApprovalRequestedOn);
// Remove all approvals over a week old
ApprovedReviews = fullResult.Where(r => r.IsApproved == true).Where(r => r.ApprovalDate != null).Where(r => r.ApprovalDate >= DateTime.Now.AddDays(-7)).OrderByDescending(r => r.ApprovalDate);
ApprovedReviews = requestedReviews.Where(r => r.IsApproved == true).Where(r => r.ApprovalDate != null).Where(r => r.ApprovalDate >= DateTime.Now.AddDays(-7)).OrderByDescending(r => r.ApprovalDate);
return Page();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public CommentsManager(

TaggableUsers = new HashSet<GithubUser>();

LoadTaggableUsers();
//Disable this to avoid exception when loading reviews for now.
// Fetch users as a background task and populate it in cache.
//LoadTaggableUsers();
}

public async void LoadTaggableUsers()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using APIViewWeb.Repositories;
using Microsoft.Azure.Cosmos;
using Microsoft.Extensions.Configuration;


namespace APIViewWeb
{
public class CosmosReviewRepository
Expand Down Expand Up @@ -116,6 +116,21 @@ public async Task<IEnumerable<ReviewModel>> GetReviewsAsync(string serviceName,
return reviews.OrderBy(r => r.Name).ThenByDescending(r => r.LastUpdated);
}

public async Task<IEnumerable<ReviewModel>> GetRequestedReviews(string userName)
{
var query = $"SELECT * FROM Reviews r WHERE IS_DEFINED(r.RequestedReviewers) AND ARRAY_CONTAINS(r.RequestedReviewers, @userName)";
var allReviews = new List<ReviewModel>();
var queryDefinition = new QueryDefinition(query).WithParameter("@userName", userName);
var itemQueryIterator = _reviewsContainer.GetItemQueryIterator<ReviewModel>(queryDefinition);
while (itemQueryIterator.HasMoreResults)
{
var result = await itemQueryIterator.ReadNextAsync();
allReviews.AddRange(result.Resource);
}

return allReviews.OrderByDescending(r => r.LastUpdated);
}

public async Task<IEnumerable<string>> GetReviewFirstLevelPropertiesAsync(string propertyName)
{
var query = $"SELECT DISTINCT VALUE r.{propertyName} FROM Reviews r";
Expand Down
7 changes: 6 additions & 1 deletion src/dotnet/APIView/APIViewWeb/Repositories/ReviewManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
Expand Down Expand Up @@ -96,6 +96,11 @@ public async Task<IEnumerable<string>> GetReviewPropertiesAsync(string propertyN
return await _reviewsRepository.GetReviewFirstLevelPropertiesAsync(propertyName);
}

public async Task<IEnumerable<ReviewModel>> GetRequestedReviews(string userName)
{
return await _reviewsRepository.GetRequestedReviews(userName);
}

public async Task<(IEnumerable<ReviewModel> Reviews, int TotalCount, int TotalPages, int CurrentPage, int? PreviousPage, int? NextPage)> GetPagedReviewsAsync(
IEnumerable<string> search, IEnumerable<string> languages, bool? isClosed, IEnumerable<int> filterTypes, bool? isApproved, int offset, int limit, string orderBy)
{
Expand Down

0 comments on commit 798f598

Please sign in to comment.