Skip to content

Commit

Permalink
ark-metadata: make elasticsearch manager optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ybensacq committed Aug 23, 2024
1 parent 5e0eb16 commit dc9e5f6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
16 changes: 16 additions & 0 deletions crates/ark-metadata/src/elasticsearch_manager.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::types::{RequestError, TokenMetadata};
use async_trait::async_trait;
pub struct NoOpElasticsearchManager;


#[cfg(any(test, feature = "mock"))]
use mockall::automock;
Expand All @@ -15,3 +17,17 @@ pub trait ElasticsearchManager {
metadata: TokenMetadata,
) -> Result<(), RequestError>;
}


#[async_trait]
impl ElasticsearchManager for NoOpElasticsearchManager {
async fn upsert_token_metadata(
&self,
_contract_address: &str,
_token_id: &str,
_chain_id: &str,
_metadata: TokenMetadata,
) -> Result<(), RequestError> {
Ok(())
}
}
18 changes: 11 additions & 7 deletions crates/ark-metadata/src/metadata_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use starknet::core::types::{BlockId, BlockTag, FieldElement};
use starknet::macros::selector;
use std::{str::FromStr, time::Duration};
use tracing::{debug, error, trace};
use crate::elasticsearch_manager::NoOpElasticsearchManager;

/// `MetadataManager` is responsible for managing metadata information related to tokens.
/// It works with the underlying storage and Starknet client to fetch and update token metadata.
Expand All @@ -24,13 +25,13 @@ pub struct MetadataManager<
T: Storage,
C: StarknetClient,
F: FileManager,
E: ElasticsearchManager,
E: ElasticsearchManager = NoOpElasticsearchManager,
> {
storage: &'a T,
starknet_client: &'a C,
request_client: ReqwestClient,
file_manager: &'a F,
elasticsearch_manager: &'a E,
elasticsearch_manager: Option<&'a E>,
}

pub struct MetadataMedia {
Expand Down Expand Up @@ -70,7 +71,7 @@ impl<'a, T: Storage, C: StarknetClient, F: FileManager, E: ElasticsearchManager>
storage: &'a T,
starknet_client: &'a C,
file_manager: &'a F,
elasticsearch_manager: &'a E,
elasticsearch_manager: Option<&'a E>,
) -> Self {
MetadataManager {
storage,
Expand Down Expand Up @@ -185,10 +186,13 @@ impl<'a, T: Storage, C: StarknetClient, F: FileManager, E: ElasticsearchManager>
.await
.map_err(MetadataError::DatabaseError)?;

self.elasticsearch_manager
.upsert_token_metadata(contract_address, token_id, chain_id, token_metadata)
.await
.map_err(|e| MetadataError::ElasticSearchError(e.to_string()))?;

if let Some(elasticsearch_manager) = self.elasticsearch_manager {
elasticsearch_manager
.upsert_token_metadata(contract_address, token_id, chain_id, token_metadata)
.await
.map_err(|e| MetadataError::ElasticSearchError(e.to_string()))?;
}

Ok(())
}
Expand Down

0 comments on commit dc9e5f6

Please sign in to comment.