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

Revert "Only update the record when fields have changed for token and metadata programs" #190

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
205 changes: 33 additions & 172 deletions program_transformers/src/asset_upserts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use {
},
},
sea_orm::{
sea_query::{Alias, Expr, OnConflict},
Condition, ConnectionTrait, DbErr, EntityTrait, Set, TransactionTrait,
sea_query::OnConflict, ConnectionTrait, DbBackend, DbErr, EntityTrait, QueryTrait, Set,
TransactionTrait,
},
serde_json::value::Value,
sqlx::types::Decimal,
Expand All @@ -33,7 +33,7 @@ pub async fn upsert_assets_token_account_columns<T: ConnectionTrait + Transactio
slot_updated_token_account: Set(columns.slot_updated_token_account),
..Default::default()
};
asset::Entity::insert(active_model)
let mut query = asset::Entity::insert(active_model)
.on_conflict(
OnConflict::columns([asset::Column::Id])
.update_columns([
Expand All @@ -42,43 +42,14 @@ pub async fn upsert_assets_token_account_columns<T: ConnectionTrait + Transactio
asset::Column::Delegate,
asset::Column::SlotUpdatedTokenAccount,
])
.action_cond_where(
Condition::all()
.add(
Condition::any()
.add(
Expr::tbl(Alias::new("excluded"), asset::Column::Owner)
.ne(Expr::tbl(asset::Entity, asset::Column::Owner)),
)
.add(
Expr::tbl(Alias::new("excluded"), asset::Column::Frozen)
.ne(Expr::tbl(asset::Entity, asset::Column::Frozen)),
)
.add(
Expr::tbl(Alias::new("excluded"), asset::Column::Delegate)
.ne(Expr::tbl(asset::Entity, asset::Column::Delegate)),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset::Column::SlotUpdatedTokenAccount,
)
.ne(Expr::tbl(
asset::Entity,
asset::Column::SlotUpdatedTokenAccount,
)),
),
)
.add_option(columns.slot_updated_token_account.map(|slot| {
Expr::tbl(asset::Entity, asset::Column::SlotUpdatedTokenAccount)
.lte(slot)
})),
)
.to_owned(),
)
.exec_without_returning(txn_or_conn)
.await?;
.build(DbBackend::Postgres);

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

Expand Down Expand Up @@ -107,8 +78,7 @@ pub async fn upsert_assets_mint_account_columns<T: ConnectionTrait + Transaction
owner_type: Set(owner_type),
..Default::default()
};

asset::Entity::insert(active_model)
let mut query = asset::Entity::insert(active_model)
.on_conflict(
OnConflict::columns([asset::Column::Id])
.update_columns([
Expand All @@ -117,32 +87,14 @@ pub async fn upsert_assets_mint_account_columns<T: ConnectionTrait + Transaction
asset::Column::SlotUpdatedMintAccount,
asset::Column::OwnerType,
])
.action_cond_where(
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),
),
)
.to_owned(),
)
.exec_without_returning(txn_or_conn)
.await?;
.build(DbBackend::Postgres);

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 @@ -192,15 +144,26 @@ 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()
};

asset::Entity::insert(active_model)
let mut query = asset::Entity::insert(active_model)
.on_conflict(
OnConflict::columns([asset::Column::Id])
.update_columns([
asset::Column::SpecificationVersion,
asset::Column::SpecificationAssetClass,
asset::Column::TreeId,
asset::Column::Nonce,
asset::Column::Seq,
asset::Column::Leaf,
asset::Column::DataHash,
asset::Column::CreatorHash,
asset::Column::Compressed,
asset::Column::Compressible,
asset::Column::RoyaltyTargetType,
asset::Column::RoyaltyTarget,
asset::Column::RoyaltyAmount,
asset::Column::AssetData,
asset::Column::SlotUpdatedMetadataAccount,
asset::Column::Burnt,
asset::Column::MplCorePlugins,
asset::Column::MplCoreUnknownPlugins,
asset::Column::MplCoreCollectionNumMinted,
Expand All @@ -209,115 +172,13 @@ pub async fn upsert_assets_metadata_account_columns<T: ConnectionTrait + Transac
asset::Column::MplCoreExternalPlugins,
asset::Column::MplCoreUnknownExternalPlugins,
])
.action_cond_where(
Condition::all()
.add(
Condition::any()
.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::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::SlotUpdatedMetadataAccount,
)
.ne(Expr::tbl(
asset::Entity,
asset::Column::SlotUpdatedMetadataAccount,
)),
)
.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),
),
)
.to_owned(),
)
.exec_without_returning(txn_or_conn)
.await?;
.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?;
Ok(())
}
Loading