Skip to content

Commit

Permalink
refactor: cleanup URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus committed Dec 6, 2024
1 parent 99edfbc commit d1a0d1b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 99 deletions.
3 changes: 0 additions & 3 deletions src/indexers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
pub use urls::*;

pub mod indexing_progress;
pub mod public_poi;
mod urls;
7 changes: 3 additions & 4 deletions src/indexers/indexing_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use thegraph_graphql_http::{
graphql::{Document, IntoDocument, IntoDocumentWithVariables},
http_client::{RequestError, ReqwestExt as _, ResponseError},
};

use super::urls::StatusUrl;
use url::Url;

const INDEXING_PROGRESS_QUERY_DOCUMENT: &str = r#"
query indexingProgress($deployments: [String!]!) {
Expand Down Expand Up @@ -41,11 +40,11 @@ pub enum Error {
/// Send a request to the indexer to get the indexing status of the given deployments.
pub async fn send_request(
client: &reqwest::Client,
url: StatusUrl,
status_url: Url,
deployments: impl IntoIterator<Item = &DeploymentId>,
) -> Result<Vec<IndexingStatusResponse>, Error> {
let resp = client
.post(url.into_inner())
.post(status_url)
.send_graphql::<Response>(Request::new(deployments))
.await
.map_err(|err| match err {
Expand Down
7 changes: 3 additions & 4 deletions src/indexers/public_poi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use thegraph_graphql_http::{
graphql::{Document, IntoDocument, IntoDocumentWithVariables},
http_client::{RequestError, ReqwestExt, ResponseError},
};

use super::urls::StatusUrl;
use url::Url;

const PUBLIC_PROOF_OF_INDEXING_QUERY_DOCUMENT: &str = r#"
query publicPois($requests: [PublicProofOfIndexingRequest!]!) {
Expand Down Expand Up @@ -54,11 +53,11 @@ impl From<(DeploymentId, BlockNumber)> for PublicProofOfIndexingRequest {
/// Send a request to the indexer to get the Public POIs of the given deployment-block number pairs.
pub async fn send_request(
client: &reqwest::Client,
url: StatusUrl,
status_url: Url,
pois: impl IntoIterator<Item = &(DeploymentId, BlockNumber)>,
) -> Result<Vec<PublicProofOfIndexingResult>, Error> {
let resp = client
.post(url.into_inner())
.post(status_url)
.send_graphql::<Response>(Request::new(pois))
.await
.map_err(|err| match err {
Expand Down
76 changes: 0 additions & 76 deletions src/indexers/urls.rs

This file was deleted.

12 changes: 5 additions & 7 deletions src/network/indexer_indexing_poi_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ impl PoiResolver {
url: &Url,
pois: &[(DeploymentId, BlockNumber)],
) -> HashMap<(DeploymentId, BlockNumber), Result<ProofOfIndexing, ResolutionError>> {
let status_url = indexers::status_url(url);
let status_url = url.join("status").unwrap();
let res = tokio::time::timeout(
self.timeout,
send_requests(&self.client, status_url, pois, POIS_PER_REQUEST_BATCH_SIZE),
send_requests(&self.client, &status_url, pois, POIS_PER_REQUEST_BATCH_SIZE),
)
.await;

Expand Down Expand Up @@ -162,7 +162,7 @@ impl PoiResolver {
/// an error if the request failed.
async fn send_requests(
client: &reqwest::Client,
url: indexers::StatusUrl,
status_url: &Url,
poi_requests: &[(DeploymentId, BlockNumber)],
batch_size: usize,
) -> HashMap<(DeploymentId, BlockNumber), Result<ProofOfIndexing, PublicPoiFetchError>> {
Expand All @@ -171,11 +171,9 @@ async fn send_requests(

// Create a request for each batch
let requests = request_batches.map(|batch| {
let url = url.clone();
let status_url = status_url.clone();
async move {
// Request the indexings' POIs
let response = indexers::public_poi::send_request(client, url.clone(), batch).await;

let response = indexers::public_poi::send_request(client, status_url, batch).await;
let result = match response {
Err(err) => {
// If the request failed, mark all deployment-block number pairs in the batch as
Expand Down
10 changes: 5 additions & 5 deletions src/network/indexer_indexing_progress_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ impl IndexingProgressResolver {
url: &Url,
indexings: &[DeploymentId],
) -> HashMap<DeploymentId, Result<Vec<ChainStatus>, ResolutionError>> {
let status_url = indexers::status_url(url);
let status_url = url.join("status").unwrap();
let res = tokio::time::timeout(
self.timeout,
send_requests(
&self.client,
status_url,
&status_url,
indexings,
INDEXINGS_PER_REQUEST_BATCH_SIZE,
),
Expand Down Expand Up @@ -132,7 +132,7 @@ impl IndexingProgressResolver {
/// as failed. The function returns a map of deployment IDs to the indexing progress information.
async fn send_requests(
client: &reqwest::Client,
url: indexers::StatusUrl,
status_url: &Url,
indexings: &[DeploymentId],
batch_size: usize,
) -> HashMap<DeploymentId, Result<Vec<ChainStatus>, IndexingProgressFetchError>> {
Expand All @@ -141,11 +141,11 @@ async fn send_requests(

// Create a request for each batch
let requests = request_batches.map(|batch| {
let url = url.clone();
let status_url = status_url.clone();
async move {
// Request the indexing progress
let response =
indexers::indexing_progress::send_request(client, url.clone(), batch).await;
indexers::indexing_progress::send_request(client, status_url, batch).await;

let result = match response {
Err(err) => {
Expand Down

0 comments on commit d1a0d1b

Please sign in to comment.