Skip to content

Commit 775d8f1

Browse files
vohoanglong0107Kobzol
authored andcommitted
perf: cache github app call
1 parent fbebfd4 commit 775d8f1

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/github/api/client.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Context;
22
use axum::async_trait;
33
use base64::Engine;
4-
use octocrab::models::{Repository, RunId};
4+
use octocrab::models::{App, Repository, RunId};
55
use octocrab::{Error, Octocrab};
66
use tracing::log;
77

@@ -14,6 +14,7 @@ use crate::github::{Branch, CommitSha, GithubRepoName, PullRequest, PullRequestN
1414

1515
/// Provides access to a single app installation (repository) using the GitHub API.
1616
pub struct GithubRepositoryClient {
17+
pub app: App,
1718
/// The client caches the access token for this given repository and refreshes it once it
1819
/// expires.
1920
pub client: Octocrab,
@@ -45,13 +46,7 @@ impl RepositoryClient for GithubRepositoryClient {
4546

4647
/// Was the comment created by the bot?
4748
async fn is_comment_internal(&self, comment: &PullRequestComment) -> anyhow::Result<bool> {
48-
let app = self
49-
.client
50-
.current()
51-
.app()
52-
.await
53-
.context("Could not load Github App")?;
54-
Ok(comment.author.html_url == app.html_url)
49+
Ok(comment.author.html_url == self.app.html_url)
5550
}
5651

5752
/// Loads repository configuration from a file located at `[CONFIG_FILE_PATH]` in the main

src/github/api/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,13 @@ async fn create_repo_state(
126126
let name = GithubRepoName::new(&owner.login, &repo.name);
127127
tracing::info!("Found repository {name}");
128128

129+
let app = repo_client
130+
.current()
131+
.app()
132+
.await
133+
.context("Could not load Github App")?;
129134
let client = GithubRepositoryClient {
135+
app,
130136
client: repo_client,
131137
repo_name: name.clone(),
132138
repository: repo,

0 commit comments

Comments
 (0)