private async Task <File> GetFile(long subscriptionId, Octokit.PullRequestFile pullRequestFile) { var fileHistory = await _dbContext.FileHistories.Where(q => q.Path == pullRequestFile.FileName && q.SubscriptionId == subscriptionId) .Include(q => q.File) .ThenInclude(q => q.Contributions) .ThenInclude(q => q.Contributor) .OrderByDescending(q => q.ContributionId) .FirstOrDefaultAsync(); return(fileHistory?.File); }
public PullRequestFileCacheItem(PullRequestFile file) { FileName = file.FileName; Sha = file.Sha; Status = (PullRequestFileStatus)Enum.Parse(typeof(PullRequestFileStatus), file.Status, true); }
private async Task <List <Contribution> > GetFolderLevelContributions(long subscriptionId, Octokit.PullRequestFile pullRequestFile) { var parts = pullRequestFile.FileName.Split('/'); var length = parts.Length - 1; var result = new List <Contribution>(); var hashSet = new HashSet <long>(); do { var path = ""; for (int i = 0; i < length; i++) { path += parts[i] + "/"; } path += "%"; // need to tune it. this really sucks performance-wise var contributions = await _dbContext.FileHistories.Where(q => q.FileHistoryType != FileHistoryType.Deleted && EF.Functions.Like(q.Path, path) && q.SubscriptionId == subscriptionId).SelectMany(q => q.File.Contributions) .Include(q => q.Contributor) .ToListAsync(); // there are duplications in the contributions foreach (var contribution in contributions) { if (hashSet.Contains(contribution.Id)) { continue; } hashSet.Add(contribution.Id); result.Add(contribution); } } while (length > 1 && result.Count == 0); return(result); }
public PullRequestDiffViewModel Init(PullRequestFilesViewModel parentViewModel, PullRequestFile pullRequestFile) { PullRequestFile = pullRequestFile; ParentViewModel = parentViewModel; return this; }