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

Merge json-uri optional arg #64

Merged
merged 30 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
353839b
Add structured logging and reduce log noisiness (#48)
NicolasPennie Apr 6, 2023
05ec5ad
Fix GetAssetsByCreator query (#8)
NicolasPennie Apr 6, 2023
9270e83
Bump to 0.7.1
NicolasPennie Apr 6, 2023
2101e81
Merge pull request #52 from helius-labs/main
linuskendall Apr 12, 2023
72f94cf
Handle HTTP errors
linuskendall Apr 13, 2023
01b34eb
Make bgtask runner configurable
linuskendall Apr 17, 2023
3ce8469
Enable configurable retries
linuskendall Apr 17, 2023
f0c3ccf
Add purged task metric
linuskendall Apr 17, 2023
6f415a5
add new task metric
linuskendall Apr 17, 2023
05d1926
Fixed nft ingester
linuskendall Apr 17, 2023
b2420e1
Fix the reading of task timeout
linuskendall Apr 17, 2023
5f63e1b
Set slow statements to debug
linuskendall Apr 17, 2023
f3020b0
Remove task name
linuskendall Apr 17, 2023
b178907
Fix purge task
linuskendall Apr 17, 2023
392a2f3
acc forwarder (#11)
ethyi Apr 19, 2023
6b27694
Fixing unused imports
linuskendall Apr 20, 2023
f2cbafd
Hopefully final fix for interval handling
linuskendall Apr 20, 2023
b8efdf2
Fix interval
linuskendall Apr 20, 2023
58cb829
Merge pull request #60 from helius-labs/main
linuskendall May 1, 2023
3c92328
fix(das-api): fix getAssetProof
NicolasPennie May 8, 2023
ee01861
Merge pull request #68 from helius-labs/main
linuskendall May 8, 2023
e1d0721
Merge pull request #55 from linuskendall/http_error_logging
linuskendall May 9, 2023
61acd9e
Merge pull request #61 from rpcpool/clean_unused_imports
linuskendall May 9, 2023
f25e468
Fix before/after cursors. (#67)
richardwu May 9, 2023
beaf042
Merge pull request #56 from rpcpool/configurable_bgtask_runner
austbot May 10, 2023
dae6d7b
Fix edition nonce (#78)
linuskendall May 30, 2023
6ae6d5f
fix(ingester): fix compressed nft burn indexing (#24) (#80)
NicolasPennie Jun 15, 2023
5d3e7a8
feat(das-api): support searching assets by `jsonUri` parameter (#79)
tsmbl Jun 21, 2023
0263776
merge json-uri optional arg
tahsintunan Jun 21, 2023
a4d0f14
fix: use IndexMap instead of BTreeMap
tahsintunan Jun 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions das_api/src/api/api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ impl ApiContract for DasApi {
page,
before,
after,
json_uri,
} = payload;
// Deserialize search assets query
self.validate_pagination(&limit, &page, &before, &after)?;
Expand Down Expand Up @@ -348,6 +349,7 @@ impl ApiContract for DasApi {
royalty_target,
royalty_amount,
burnt,
json_uri,
};
let sort_by = sort_by.unwrap_or_default();
let transform = AssetTransform {
Expand Down
2 changes: 2 additions & 0 deletions das_api/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ pub struct SearchAssets {
pub page: Option<u32>,
pub before: Option<String>,
pub after: Option<String>,
#[serde(default)]
pub json_uri: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
Expand Down
19 changes: 19 additions & 0 deletions digital_asset_types/src/dao/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct SearchAssetsQuery {
pub royalty_target: Option<Vec<u8>>,
pub royalty_amount: Option<u32>,
pub burnt: Option<bool>,
pub json_uri: Option<String>,
}

impl SearchAssetsQuery {
Expand Down Expand Up @@ -111,6 +112,9 @@ impl SearchAssetsQuery {
if self.grouping.is_some() {
num_conditions += 1;
}
if self.json_uri.is_some() {
num_conditions += 1;
}

num_conditions
}
Expand Down Expand Up @@ -223,6 +227,21 @@ impl SearchAssetsQuery {
joins.push(rel);
}

if let Some(ju) = self.json_uri.to_owned() {
let cond = Condition::all()
.add(asset_data::Column::MetadataUrl.eq(ju));
conditions = conditions.add(cond);
let rel = asset_data::Relation::Asset
.def()
.rev()
.on_condition(|left, right| {
Expr::tbl(right, asset_data::Column::Id)
.eq(Expr::tbl(left, asset::Column::AssetData))
.into_condition()
});
joins.push(rel);
}

Ok((
match self.negate {
None | Some(false) => conditions,
Expand Down
45 changes: 28 additions & 17 deletions digital_asset_types/src/dao/scopes/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::dao::{
asset, asset_authority, asset_creators, asset_data, asset_grouping, cl_audits, FullAsset,
GroupingSize, Pagination,
};
use indexmap::IndexMap;
use sea_orm::{entity::*, query::*, ConnectionTrait, DbErr, Order};
use std::collections::{BTreeMap, HashMap};

pub fn paginate<'db, T>(pagination: &Pagination, limit: u64, stmt: T) -> T
where
Expand Down Expand Up @@ -156,7 +156,6 @@ where
E: RelationTrait,
{
let mut stmt = asset::Entity::find()
.find_also_related(asset_data::Entity)
.filter(condition)
.join(JoinType::LeftJoin, relation.def())
.order_by(sort_by, sort_direction);
Expand All @@ -170,27 +169,39 @@ where

pub async fn get_related_for_assets(
conn: &impl ConnectionTrait,
assets: Vec<(asset::Model, Option<asset_data::Model>)>,
assets: Vec<asset::Model>,
) -> Result<Vec<FullAsset>, DbErr> {
let mut ids = Vec::with_capacity(assets.len());
// Using IndexMap to preserve order.
let mut assets_map = assets.into_iter().fold(IndexMap::new(), |mut x, asset| {
if let Some(ad) = asset.1 {
let id = asset.0.id.clone();
let asset_ids = assets.iter().map(|a| a.id.clone()).collect::<Vec<_>>();

let asset_data: Vec<asset_data::Model> = asset_data::Entity::find()
.filter(asset_data::Column::Id.is_in(asset_ids))
.all(conn)
.await?;
let asset_data_map = asset_data.into_iter().fold(HashMap::new(), |mut acc, ad| {
acc.insert(ad.id.clone(), ad);
acc
});

// Using BTreeMap to preserve order.
let mut assets_map = assets.into_iter().fold(BTreeMap::new(), |mut acc, asset| {
if let Some(ad) = asset
.asset_data
.clone()
.and_then(|ad_id| asset_data_map.get(&ad_id))
{
let id = asset.id.clone();
let fa = FullAsset {
asset: asset.0,
data: ad,
asset: asset,
data: ad.clone(),
authorities: vec![],
creators: vec![],
groups: vec![],
};

x.insert(id.clone(), fa);
ids.push(id);
}
x
acc.insert(id, fa);
};
acc
});

let ids = assets_map.keys().cloned().collect::<Vec<_>>();
let authorities = asset_authority::Entity::find()
.filter(asset_authority::Column::AssetId.is_in(ids.clone()))
.order_by_asc(asset_authority::Column::AssetId)
Expand Down Expand Up @@ -243,7 +254,7 @@ pub async fn get_assets_by_condition(
stmt = stmt.filter(condition).order_by(sort_by, sort_direction);

stmt = paginate(pagination, limit, stmt);
let asset_list = stmt.find_also_related(asset_data::Entity).all(conn).await?;
let asset_list = stmt.all(conn).await?;
get_related_for_assets(conn, asset_list).await
}

Expand Down