public static MutableIndexChanges Upsert(this VersionLists versionList, VersionProperties version) { return(versionList.Upsert(version.FullVersion, version.Data)); }
public async Task <IndexActions> UpdateAsync(string packageId, Func <SearchFilters, KeyedDocument> buildDocument) { var versionListDataResult = await _versionListDataClient.ReadAsync(packageId); var versionLists = new VersionLists(versionListDataResult.Result); /// Update all of the search documents that exist for this package ID with the provided document builder. /// Here are some examples of different search filter combinations that could occur. /// /// Example #1: 1.0.0 (listed) /// /// A stable SemVer 1.0.0 package matches all search filters, so one index action will be produced for /// each search document. That is four in total. All of these search documents have the same latest /// version: 1.0.0. /// /// Example #2: 1.0.0 (unlisted), 2.0.0 (unlisted) /// /// There are no search documents at all in this case since there is no listed version. No index actions /// are produced in this case. /// /// Example #3: 1.0.0-beta (listed), 2.0.0-beta.1 (listed) /// /// All of the versions are prerelease so there are no search documents for "stable" search filters. There /// two search documents to be updated, one for <see cref="SearchFilters.IncludePrerelease"/> and one for /// <see cref="SearchFilters.IncludePrereleaseAndSemVer2"/>. The latest version for each of these two /// documents is different. var search = new List <IndexAction <KeyedDocument> >(); var searchFilters = new List <SearchFilters>(); foreach (var searchFilter in DocumentUtilities.AllSearchFilters) { // Determine if there is a document for this ID and search filter. if (versionLists.GetLatestVersionInfoOrNull(searchFilter) == null) { continue; } var document = buildDocument(searchFilter); var indexAction = IndexAction.Merge(document); search.Add(indexAction); searchFilters.Add(searchFilter); } _logger.LogInformation( "Package ID {PackageId} has {Count} search document changes for search filters: {SearchFilters}", packageId, searchFilters.Count, searchFilters); // No changes are made to the hijack index. var hijack = new List <IndexAction <KeyedDocument> >(); // We never make any change to the version list but still want to push it back to storage. This will give // us an etag mismatch if the version list has changed. This is good because if the version list has // changed it's possible there is another search document that we have to update. If we didn't do this, // then a race condition could occur where one of the search documents for an ID would not get an update. var newVersionListDataResult = versionListDataResult; return(new IndexActions( search, hijack, newVersionListDataResult)); }
public static MutableIndexChanges Delete(this VersionLists versionList, string fullOrOriginalVersion) { return(versionList.Delete(NuGetVersion.Parse(fullOrOriginalVersion))); }
public SearchDocument.LatestFlags LatestFlagsOrNull(VersionLists versionLists, SearchFilters searchFilters) { var latest = versionLists.GetLatestVersionInfoOrNull(searchFilters); if (latest == null) { return(null); } // The latest version, given the "include prerelease" bit of the search filter, may or may not be the // absolute latest version when considering both prerelease and stable versions. Consider the following // cases: // // Case #1: // SearchFilters.Default: // All versions: 1.0.0, 2.0.0-alpha // Latest version given filters: 1.0.0 // V2 search document flags: // IsLatestStable = true // IsLatest = false // // Case #2: // SearchFilters.Default: // All versions: 1.0.0 // Latest version given filters: 1.0.0 // V2 search document flags: // IsLatestStable = true // IsLatest = true // // Case #3: // SearchFilters.IncludePrerelease: // All versions: 1.0.0, 2.0.0-alpha // Latest version given filters: 2.0.0-alpha // V2 search document flags: // IsLatestStable = false // IsLatest = true // // Case #4: // SearchFilters.IncludePrerelease: // All versions: 1.0.0 // Latest version given filters: 1.0.0 // V2 search document flags: // IsLatestStable = true // IsLatest = true // // In cases #1 and #2, we know the value of IsLatestStable will always be true. We cannot know whether // IsLatest is true or false without looking at the version list that includes prerelease versions. For // cases #3 and #4, we know IsLatest will always be true and we can determine IsLatestStable by looking // at whether the latest version is prerelease or not. bool isLatestStable; bool isLatest; if ((searchFilters & SearchFilters.IncludePrerelease) == 0) { // This is the case where prerelease versions are excluded. var latestIncludePrerelease = versionLists .GetLatestVersionInfoOrNull(searchFilters | SearchFilters.IncludePrerelease); Guard.Assert( latestIncludePrerelease != null, "If a search filter excludes prerelease and has a latest version, then there is a latest version including prerelease."); isLatestStable = true; isLatest = latestIncludePrerelease.ParsedVersion == latest.ParsedVersion; } else { // This is the case where prerelease versions are included. isLatestStable = !latest.ParsedVersion.IsPrerelease; isLatest = true; } return(new SearchDocument.LatestFlags(latest, isLatestStable, isLatest)); }