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

adds a new version to the /vaults endpoint to list cache duration #31

Merged
merged 2 commits into from
Mar 22, 2024

Conversation

brunocalza
Copy link
Collaborator

@brunocalza brunocalza commented Mar 21, 2024

Summary

This PR adds a /v2/vault endpoint that lists the vaults from a given account and the cache duration of that vault.
We needed to add a version because the response is a breaking change.

Here's a response sample:

[
  {
    "vault": "api50.test",
    "cache_duration": null
  },
  {
    "vault": "api51.test",
    "cache_duration": 10
  }
]

Goes together with tablelandnetwork/basin-cli#41 and closes ENG-761

@@ -70,17 +70,40 @@ pub async fn is_namespace_owner(pool: &PgPool, ns: &str, owner: Address) -> Resu
Ok(!res.is_empty())
}

/// Returns cache config
pub async fn get_cache_config(pool: &PgPool, ns: &str, rel: &str) -> Result<Option<i64>> {
/// Returns cache config from a vault
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a refactor

.fetch_one(pool)
.await
.unwrap_or((None, ));
Ok(duration)
}

pub async fn find_cache_config_by_vaults(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new db method that fetches all configs at once for a list of vaults. the query is a bit complicated because of how the schema of the database is structured

@@ -150,6 +151,82 @@ pub async fn find_vaults_by_account<E: EVMClient + 'static + std::marker::Sync>(
Ok(with_status(json(&vaults), StatusCode::OK))
}

pub async fn find_vaults_by_account_v2<E: EVMClient + 'static + std::marker::Sync>(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handler for v2

@@ -39,6 +39,7 @@ mod api {
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
health()
.or(vaults_list(evm_client.clone()))
.or(vaults_list_v2(evm_client.clone(), db.clone()))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hooks new route

@@ -67,6 +68,19 @@ mod api {
.and_then(routes::find_vaults_by_account)
}

// GET /v2/vaults
pub fn vaults_list_v2<E: EVMClient + 'static + std::marker::Sync>(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new http route

@@ -145,6 +145,18 @@ impl TestApp {
.expect("Failed to execute request.")
}

pub async fn get_vaults_v2(&self) -> Response {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test helper for v2

@@ -37,6 +37,37 @@ async fn list_vaults() {
assert_eq!(json!(["api.test", "api.test2"]), response);
}

#[tokio::test]
async fn list_vaults_v2() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new test for v2

@brunocalza brunocalza self-assigned this Mar 21, 2024
@brunocalza brunocalza marked this pull request as ready for review March 21, 2024 19:19
@@ -1,7 +1,7 @@
use regex::Regex;
use std::fmt;

#[derive(Debug)]
#[derive(Debug, Clone)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, if you burrow the Vault in this function: find_cache_config_by_vaults, you may not need to implement Clone here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! yeah, that works. I still tend to just clone to solve the compiler complaint 😅

Signed-off-by: Bruno Calza <[email protected]>
@brunocalza brunocalza merged commit 052aa1a into bcalza/fixtimestampquery Mar 22, 2024
5 checks passed
@brunocalza brunocalza deleted the bcalza/listcacheduration branch March 22, 2024 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants