Skip to content

Commit

Permalink
fix(ark-metadata): make elasticsearch optionnal (#426)
Browse files Browse the repository at this point in the history
## Description

1. make elasticsearch optionnal

<!--
Please do not leave this blank.
Describe the changes in this PR. What does it [add/remove/fix/replace]?

For crafting a good description, consider using ChatGPT to help
articulate your changes.
-->

## What type of PR is this? (check all applicable)

- [ ] 🍕 Feature (`feat:`)
- [ ] 🐛 Bug Fix (`fix:`)
- [ ] 📝 Documentation Update (`docs:`)
- [ ] 🎨 Style (`style:`)
- [ ] 🧑‍💻 Code Refactor (`refactor:`)
- [ ] 🔥 Performance Improvements (`perf:`)
- [ ] ✅ Test (`test:`)
- [ ] 🤖 Build (`build:`)
- [ ] 🔁 CI (`ci:`)
- [ ] 📦 Chore (`chore:`)
- [ ] ⏩ Revert (`revert:`)
- [ ] 🚀 Breaking Changes (`BREAKING CHANGE:`)

## Related Tickets & Documents

<!--
Please use this format to link related issues: Fixes #<issue_number>
More info:
https://docs.github.com/en/free-pro-team@latest/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword
-->

## Added tests?

- [ ] 👍 yes
- [ ] 🙅 no, because they aren't needed
- [ ] 🙋 no, because I need help

## Added to documentation?

- [ ] 📜 README.md
- [ ] 📓 Documentation
- [ ] 🙅 no documentation needed

## [optional] Are there any post-deployment tasks we need to perform?

<!-- Describe any additional tasks, if any, and provide steps. -->

## [optional] What gif best describes this PR or how it makes you feel?

<!-- Share a fun gif related to your PR! -->

### PR Title and Description Guidelines:

- Ensure your PR title follows semantic versioning standards. This helps
automate releases and changelogs.
- Use types like `feat:`, `fix:`, `chore:`, `BREAKING CHANGE:` etc. in
your PR title.
- Your PR title will be used as a commit message when merging. Make sure
it adheres to [Conventional Commits
standards](https://www.conventionalcommits.org/).

## Closing Issues

<!--
Use keywords to close related issues. This ensures that the associated
issues will automatically close when the PR is merged.

- `Fixes #123` will close issue 123 when the PR is merged.
- `Closes #123` will also close issue 123 when the PR is merged.
- `Resolves #123` will also close issue 123 when the PR is merged.

You can also use multiple keywords in one comment:
- `Fixes #123, Resolves #456`

More info:
https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->
  • Loading branch information
ybensacq authored Aug 23, 2024
1 parent 5e0eb16 commit 25aab1c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
14 changes: 14 additions & 0 deletions crates/ark-metadata/src/elasticsearch_manager.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 +16,16 @@ 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(())
}
}
23 changes: 13 additions & 10 deletions crates/ark-metadata/src/metadata_manager.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::elasticsearch_manager::NoOpElasticsearchManager;
use crate::{
elasticsearch_manager::ElasticsearchManager,
file_manager::{FileInfo, FileManager},
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,12 @@ 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 Expand Up @@ -496,7 +499,7 @@ mod tests {
&storage_manager,
&mock_client,
&mock_file,
&mock_elasticsearch_manager,
Some(&mock_elasticsearch_manager),
);

// EXECUTION: Call the function under test
Expand Down Expand Up @@ -580,7 +583,7 @@ mod tests {
&mock_storage,
&mock_client,
&mock_file,
&mock_elasticsearch_manager,
Some(&mock_elasticsearch_manager),
);

// EXECUTION: Call the function under test
Expand Down Expand Up @@ -633,7 +636,7 @@ mod tests {
&storage_manager,
&mock_client,
&mock_file,
&mock_elasticsearch_manager,
Some(&mock_elasticsearch_manager),
);

// EXECUTION: Call the function under test
Expand Down

0 comments on commit 25aab1c

Please sign in to comment.