0

我正在尝试使用 Octokit.net 在一个简单的 C# 控制台应用程序(Visual Studio 2019、.NETCore 3.1)中与 GitHub 交互,但我遇到了一个极其缓慢的问题。

Postman 使用以下 GET 请求直接调用 GitHub api:

https://api.github.com/repos/OrganizationName/RepoName/commits

最多在1500 毫秒内提供响应,同时通过以下方式获取相同的信息:

var client = new GitHubClient(new ProductHeaderValue("my-test"));
client.Credentials = new Credentials(MY_TOKEN); //same token used in Authentication header when calling API by Postman

Console.WriteLine(DateTime.Now + " Begin to await...");

IReadOnlyList<GitHubCommit> commits = await client.Repository.Commit.GetAll("OrganizationName", "RepoName");

Console.WriteLine(DateTime.Now + " Await finished...");

让我等3分钟

关于如何将过程加速到最多几秒钟的任何想法?

- - 编辑

正如Jon Skeet在评论中指出的那样,我由 Postman 发送的请求更快,因为它只检索一页提交,而我的 Octokit 代码实际上检索所有提交。

通过以下编辑,Octokit 只检索 100 个提交的单页:

ApiOptions options = new ApiOptions
            {
                PageSize = 101,
                PageCount = 1
            };
IReadOnlyList<GitHubCommit> commits = await client.Repository.Commit.GetAll("OrganizationName", "RepoName", options);
4

0 回答 0