Skip to content

Commit

Permalink
Modified logic in GetVersionedPackageEntriesFromSearchQueryResource t…
Browse files Browse the repository at this point in the history
…o support CodeArtifact
  • Loading branch information
Andrew Pearce committed Jun 14, 2024
1 parent fc32844 commit 51cc37b
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/code/V3ServerAPICalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -873,22 +873,27 @@ private List<JsonElement> GetVersionedPackageEntriesFromSearchQueryResource(stri
return pkgEntries;
}

// Get initial response
int skip = 0;
string query = $"{searchQueryServiceUrl}?q={queryTerm}&prerelease={includePrerelease}&semVerLevel=2.0.0&skip={skip}&take=100";
int skipAndTakeAmount = 100;
if (_isAWSCodeArtifactRepo) {
skipAndTakeAmount = 25;
}

// Get responses for all packages that contain the required tags
pkgEntries.AddRange(GetJsonElementArr(query, dataName, out int initialCount, out errRecord).ToList());
// Get initial response
string query = $"{searchQueryServiceUrl}?q={queryTerm}&prerelease={includePrerelease}&semVerLevel=2.0.0&skip={skip}&take={skipAndTakeAmount}";

// check count (ie "totalHits") 425 ==> count/100 ~~> 4 calls ~~> + 1 = 5 calls
int count = initialCount / 100 + 1;
// if more than 100 count, loop and add response to list
while (count > 0)
{
skip += 100;
query = $"{searchQueryServiceUrl}?q={queryTerm}&prerelease={includePrerelease}&semVerLevel=2.0.0&skip={skip}&take=100";
pkgEntries.AddRange(GetJsonElementArr(query, dataName, out int unneededCount, out errRecord).ToList());
count--;
var itemList = GetJsonElementArr(query, dataName, out int initialCount, out errRecord).ToList();
pkgEntries.AddRange(itemList);

// Get responses for all packages that contain the required tags
while (itemList.Count > 0) {
skip += skipAndTakeAmount;
query = $"{searchQueryServiceUrl}?q={queryTerm}&prerelease={includePrerelease}&semVerLevel=2.0.0&skip={skip}&take={skipAndTakeAmount}";
itemList = GetJsonElementArr(query, dataName, out int unneededCount, out errRecord).ToList();
if (itemList.Count == 0) {
break;
}
pkgEntries.AddRange(itemList);
}

return pkgEntries;
Expand Down

0 comments on commit 51cc37b

Please sign in to comment.