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

Remove duplicate results for same asset_ids in get_assets rpc method #227

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

AhzamAkhtar
Copy link

Problem
In getAssets rpc method , a user can provide multiple same asset_id to search for, and the api will give that many duplicated results, instead we can return a single result.

Tasks

  • Remove duplicate results
  • tests

@@ -230,9 +241,13 @@ impl ApiContract for DasApi {

let options = options.unwrap_or_default();

let assets = get_assets(&self.db_connection, id_bytes, batch_size as u64, &options).await?;
let unique_asset_ids = remove_duplicates_asset_ids(id_bytes);
Copy link
Collaborator

Choose a reason for hiding this comment

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

filter dup ids at line no 237 and then convert to Vec<Vec<_>>

@@ -148,6 +149,16 @@ pub fn not_found(asset_id: &String) -> DbErr {
DbErr::RecordNotFound(format!("Asset Proof for {} Not Found", asset_id))
}

pub fn remove_duplicates_asset_ids(id_bytes: Vec<Vec<u8>>) -> Vec<Vec<u8>> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can use generics here

@AhzamAkhtar
Copy link
Author

suggested improvments implemented @Nagaprasadvr

@@ -218,6 +224,7 @@ impl ApiContract for DasApi {
) -> Result<Vec<Option<Asset>>, DasApiError> {
let GetAssets { ids, options } = payload;

let ids = remove_duplicates_ids(ids);
Copy link
Author

Choose a reason for hiding this comment

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

also dont need to use generic now cause now we filtering only ids, which is Vec

Copy link
Contributor

@danenbm danenbm left a comment

Choose a reason for hiding this comment

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

LGTM

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.

3 participants