Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve load times by offloading requests to multiple tokens #101

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ jobs:
env:
PIDGTM_DATABASE_URL: ${{ secrets.PIDGTM_DATABASE_URL }}
STARTGG_TOKEN: ${{ secrets.STARTGG_TOKEN }}
STARTGG_TOKEN_1: ${{ secrets.STARTGG_TOKEN_1 }}
STARTGG_TOKEN_2: ${{ secrets.STARTGG_TOKEN_2 }}
STARTGG_TOKEN_3: ${{ secrets.STARTGG_TOKEN_3 }}
STARTGG_TOKEN_4: ${{ secrets.STARTGG_TOKEN_4 }}
STARTGG_TOKEN_5: ${{ secrets.STARTGG_TOKEN_5 }}
STARTGG_TOKEN_6: ${{ secrets.STARTGG_TOKEN_6 }}

- name: Upload Code Coverage Results
uses: codecov/codecov-action@v3
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 33 additions & 3 deletions backend-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,42 @@ spec:
- name: PIDGTM_DATABASE_URL
valueFrom:
secretKeyRef:
name: backend-secrets
name: backend-secrets-multiple-tokens
key: PIDGTM_DATABASE_URL
- name: STARTGG_TOKEN
valueFrom:
secretKeyRef:
name: backend-secrets
name: backend-secrets-multiple-tokens
key: STARTGG_TOKEN
- name: STARTGG_TOKEN_1
valueFrom:
secretKeyRef:
name: backend-secrets-multiple-tokens
key: STARTGG_TOKEN_1
- name: STARTGG_TOKEN_2
valueFrom:
secretKeyRef:
name: backend-secrets-multiple-tokens
key: STARTGG_TOKEN_2
- name: STARTGG_TOKEN_3
valueFrom:
secretKeyRef:
name: backend-secrets-multiple-tokens
key: STARTGG_TOKEN_3
- name: STARTGG_TOKEN_4
valueFrom:
secretKeyRef:
name: backend-secrets-multiple-tokens
key: STARTGG_TOKEN_4
- name: STARTGG_TOKEN_5
valueFrom:
secretKeyRef:
name: backend-secrets-multiple-tokens
key: STARTGG_TOKEN_5
- name: STARTGG_TOKEN_6
valueFrom:
secretKeyRef:
name: backend-secrets-multiple-tokens
key: STARTGG_TOKEN_6
nodeSelector:
node: rpileaf02
node: rpileaf02
3 changes: 2 additions & 1 deletion startgg_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ anyhow = "1"
gql_client = "1"
serde = "1"
as-any = "0.3"
tokio = { version = "1.1", features = [ "rt", "macros" ] }
tokio = { version = "1.1", features = [ "rt", "macros" ] }
rand = "0.8"
26 changes: 22 additions & 4 deletions startgg_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@
impl StartGG {
pub fn connect() -> Self {
let mut headers = HashMap::new();
let bearer_token = format!(
"Bearer {}",
std::env::var("STARTGG_TOKEN").expect("could not find STARTGG_TOKEN env var")
);
let bearer_token = format!("Bearer {}", get_random_startgg_token());

Check warning on line 202 in startgg_api/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

startgg_api/src/lib.rs#L202

Added line #L202 was not covered by tests
headers.insert("authorization", bearer_token.as_str());
Self {
gql_client: gql_client::Client::new_with_headers(STARTGG_ENDPOINT, headers),
Expand All @@ -214,6 +211,19 @@
}
}

// Function to randomly get a STARTGG_TOKEN between STARTGG_TOKEN_1 and STARTGG_TOKEN_6
pub fn get_random_startgg_token() -> String {
let random_number = rand::random::<u8>() % 6 + 1;
let STARTGG_TOKEN = format!("STARTGG_TOKEN_{}", random_number);
match std::env::var(format!("STARTGG_TOKEN_{}", random_number)) {
Ok(token) => token,

Check warning on line 219 in startgg_api/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

startgg_api/src/lib.rs#L215-L219

Added lines #L215 - L219 were not covered by tests
Err(_) => {
eprintln!("Token not found for {}", STARTGG_TOKEN);
std::env::var("STARTGG_TOKEN").expect("STARTGG_TOKEN not found")

Check warning on line 222 in startgg_api/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

startgg_api/src/lib.rs#L221-L222

Added lines #L221 - L222 were not covered by tests
}
}
}

Check warning on line 225 in startgg_api/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

startgg_api/src/lib.rs#L225

Added line #L225 was not covered by tests

pub const SSBU_CHARACTERS: [(i32, &str); 87] = [
(1271, "Bayonetta"),
(1272, "Bowser Jr."),
Expand Down Expand Up @@ -303,3 +313,11 @@
(1846, "Kazuya"),
(1897, "Sora"),
];

#[cfg(test)]
mod tests {
#[test]
fn test_get_random_startgg_token() {
dbg!(crate::get_random_startgg_token());
}
}
Loading