Skip to content

Commit

Permalink
Revert "Only update the record when fields have changed (#187)" (#190)
Browse files Browse the repository at this point in the history
This reverts commit 449eb45.
  • Loading branch information
kespinola committed Dec 18, 2024
1 parent 6e30dd8 commit bf74b4b
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 544 deletions.
173 changes: 33 additions & 140 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 Down Expand Up @@ -66,9 +66,12 @@ pub async fn upsert_assets_token_account_columns<T: ConnectionTrait + Transactio
)
.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 @@ -97,8 +100,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 @@ -107,32 +109,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 @@ -182,15 +166,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 @@ -199,115 +194,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

0 comments on commit bf74b4b

Please sign in to comment.