Skip to content

Commit

Permalink
Add field noop checks on mpl and asset upserts
Browse files Browse the repository at this point in the history
  • Loading branch information
kespinola committed Dec 19, 2024
1 parent 49b1e41 commit d3aaae8
Show file tree
Hide file tree
Showing 3 changed files with 691 additions and 90 deletions.
295 changes: 281 additions & 14 deletions program_transformers/src/asset_upserts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use {
},
sea_orm::{
sea_query::{Alias, Condition, Expr, OnConflict},
ConnectionTrait, DbBackend, DbErr, EntityTrait, QueryTrait, Set, TransactionTrait,
ConnectionTrait, DbErr, EntityTrait, Set, TransactionTrait,
},
serde_json::value::Value,
sqlx::types::Decimal,
Expand Down Expand Up @@ -138,7 +138,7 @@ pub async fn upsert_assets_mint_account_columns<T: ConnectionTrait + Transaction
owner_type: Set(owner_type),
..Default::default()
};
let mut query = asset::Entity::insert(active_model)
asset::Entity::insert(active_model)
.on_conflict(
OnConflict::columns([asset::Column::Id])
.update_columns([
Expand All @@ -147,14 +147,51 @@ pub async fn upsert_assets_mint_account_columns<T: ConnectionTrait + Transaction
asset::Column::SlotUpdatedMintAccount,
asset::Column::OwnerType,
])
.action_cond_where(
Condition::any()
.add(
Condition::all()
.add(
Condition::any()
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::Supply,
)
.ne(Expr::tbl(asset::Entity, asset::Column::Supply)),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::SupplyMint,
)
.ne(
Expr::tbl(asset::Entity, asset::Column::SupplyMint),
),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::OwnerType,
)
.ne(Expr::tbl(asset::Entity, asset::Column::OwnerType)),
),
)
.add(
Expr::tbl(asset::Entity, asset::Column::SlotUpdatedMintAccount)
.lte(columns.slot_updated_mint_account as i64),
),
)
.add(
Expr::tbl(asset::Entity, asset::Column::SlotUpdatedMintAccount)
.is_null(),
),
)
.to_owned(),
)
.build(DbBackend::Postgres);
.exec_without_returning(txn_or_conn)
.await?;

query.sql = format!(
"{} WHERE excluded.slot_updated_mint_account >= asset.slot_updated_mint_account OR asset.slot_updated_mint_account IS NULL",
query.sql);
txn_or_conn.execute(query).await?;
Ok(())
}

Expand Down Expand Up @@ -204,7 +241,7 @@ pub async fn upsert_assets_metadata_account_columns<T: ConnectionTrait + Transac
mpl_core_unknown_external_plugins: Set(columns.mpl_core_unknown_external_plugins),
..Default::default()
};
let mut query = asset::Entity::insert(active_model)
asset::Entity::insert(active_model)
.on_conflict(
OnConflict::columns([asset::Column::Id])
.update_columns([
Expand Down Expand Up @@ -232,13 +269,243 @@ pub async fn upsert_assets_metadata_account_columns<T: ConnectionTrait + Transac
asset::Column::MplCoreExternalPlugins,
asset::Column::MplCoreUnknownExternalPlugins,
])
.action_cond_where(
Condition::any()
.add(
Condition::all()
.add(
Condition::any()
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::SpecificationVersion,
)
.ne(
Expr::tbl(
asset::Entity,
asset::Column::SpecificationVersion,
),
),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::SpecificationAssetClass,
)
.ne(
Expr::tbl(
asset::Entity,
asset::Column::SpecificationAssetClass,
),
),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::TreeId,
)
.ne(Expr::tbl(asset::Entity, asset::Column::TreeId)),
)
.add(
Expr::tbl(Alias::new("excluded"), asset::Column::Nonce)
.ne(Expr::tbl(asset::Entity, asset::Column::Nonce)),
)
.add(
Expr::tbl(Alias::new("excluded"), asset::Column::Seq)
.ne(Expr::tbl(asset::Entity, asset::Column::Seq)),
)
.add(
Expr::tbl(Alias::new("excluded"), asset::Column::Leaf)
.ne(Expr::tbl(asset::Entity, asset::Column::Leaf)),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::DataHash,
)
.ne(Expr::tbl(asset::Entity, asset::Column::DataHash)),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::CreatorHash,
)
.ne(
Expr::tbl(
asset::Entity,
asset::Column::CreatorHash,
),
),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::Compressed,
)
.ne(
Expr::tbl(asset::Entity, asset::Column::Compressed),
),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::Compressible,
)
.ne(
Expr::tbl(
asset::Entity,
asset::Column::Compressible,
),
),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::RoyaltyTargetType,
)
.ne(
Expr::tbl(
asset::Entity,
asset::Column::RoyaltyTargetType,
),
),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::RoyaltyTarget,
)
.ne(
Expr::tbl(
asset::Entity,
asset::Column::RoyaltyTarget,
),
),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::RoyaltyAmount,
)
.ne(
Expr::tbl(
asset::Entity,
asset::Column::RoyaltyAmount,
),
),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::AssetData,
)
.ne(Expr::tbl(asset::Entity, asset::Column::AssetData)),
)
.add(
Expr::tbl(Alias::new("excluded"), asset::Column::Burnt)
.ne(Expr::tbl(asset::Entity, asset::Column::Burnt)),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::MplCorePlugins,
)
.ne(
Expr::tbl(
asset::Entity,
asset::Column::MplCorePlugins,
),
),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::MplCoreUnknownPlugins,
)
.ne(
Expr::tbl(
asset::Entity,
asset::Column::MplCoreUnknownPlugins,
),
),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::MplCoreCollectionNumMinted,
)
.ne(
Expr::tbl(
asset::Entity,
asset::Column::MplCoreCollectionNumMinted,
),
),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::MplCoreCollectionCurrentSize,
)
.ne(
Expr::tbl(
asset::Entity,
asset::Column::MplCoreCollectionCurrentSize,
),
),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::MplCorePluginsJsonVersion,
)
.ne(
Expr::tbl(
asset::Entity,
asset::Column::MplCorePluginsJsonVersion,
),
),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::MplCoreExternalPlugins,
)
.ne(
Expr::tbl(
asset::Entity,
asset::Column::MplCoreExternalPlugins,
),
),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::MplCoreUnknownExternalPlugins,
)
.ne(
Expr::tbl(
asset::Entity,
asset::Column::MplCoreUnknownExternalPlugins,
),
),
),
)
.add(
Expr::tbl(
asset::Entity,
asset::Column::SlotUpdatedMetadataAccount,
)
.lte(columns.slot_updated_metadata_account as i64),
),
)
.add(
Expr::tbl(asset::Entity, asset::Column::SlotUpdatedMetadataAccount)
.is_null(),
),
)
.to_owned(),
)
.build(DbBackend::Postgres);

query.sql = format!(
"{} WHERE excluded.slot_updated_metadata_account >= asset.slot_updated_metadata_account OR asset.slot_updated_metadata_account IS NULL",
query.sql);
txn_or_conn.execute(query).await?;
.exec_without_returning(txn_or_conn)
.await?;
Ok(())
}
Loading

0 comments on commit d3aaae8

Please sign in to comment.