From 5a0b4375c4e5ee32eb995426d3009242c60b006f Mon Sep 17 00:00:00 2001 From: rtso <8248583+rtso@users.noreply.github.com> Date: Fri, 3 May 2024 20:44:40 -0700 Subject: [PATCH] Fix current inserts --- .../processors/fungible_asset_processor.rs | 31 +++++++++-- .../src/processors/token_v2_processor.rs | 52 +++++++++++++++++-- 2 files changed, 74 insertions(+), 9 deletions(-) diff --git a/rust/processor/src/processors/fungible_asset_processor.rs b/rust/processor/src/processors/fungible_asset_processor.rs index 02f64a9b7..c5f303b17 100644 --- a/rust/processor/src/processors/fungible_asset_processor.rs +++ b/rust/processor/src/processors/fungible_asset_processor.rs @@ -159,11 +159,21 @@ fn insert_fungible_asset_metadata_query( .do_update() .set( ( - supply_v2.eq(excluded(supply_v2)), - maximum_v2.eq(excluded(maximum_v2)), + creator_address.eq(excluded(creator_address)), + name.eq(excluded(name)), + symbol.eq(excluded(symbol)), decimals.eq(excluded(decimals)), + icon_uri.eq(excluded(icon_uri)), + project_uri.eq(excluded(project_uri)), + last_transaction_version.eq(excluded(last_transaction_version)), + last_transaction_timestamp.eq(excluded(last_transaction_timestamp)), + supply_aggregator_table_handle_v1.eq(excluded(supply_aggregator_table_handle_v1)), + supply_aggregator_table_key_v1.eq(excluded(supply_aggregator_table_key_v1)), + token_standard.eq(excluded(token_standard)), inserted_at.eq(excluded(inserted_at)), is_token_v2.eq(excluded(is_token_v2)), + supply_v2.eq(excluded(supply_v2)), + maximum_v2.eq(excluded(maximum_v2)), ) ), Some(" WHERE fungible_asset_metadata.last_transaction_version <= excluded.last_transaction_version "), @@ -199,8 +209,21 @@ fn insert_current_fungible_asset_balances_query( diesel::insert_into(schema::current_fungible_asset_balances::table) .values(items_to_insert) .on_conflict(storage_id) - .do_nothing(), - None, + .do_update() + .set( + ( + owner_address.eq(excluded(owner_address)), + asset_type.eq(excluded(asset_type)), + is_primary.eq(excluded(is_primary)), + is_frozen.eq(excluded(is_frozen)), + amount.eq(excluded(amount)), + last_transaction_timestamp.eq(excluded(last_transaction_timestamp)), + last_transaction_version.eq(excluded(last_transaction_version)), + token_standard.eq(excluded(token_standard)), + inserted_at.eq(excluded(inserted_at)), + ) + ), + Some(" WHERE current_fungible_asset_balances.last_transaction_version <= excluded.last_transaction_version "), ) } diff --git a/rust/processor/src/processors/token_v2_processor.rs b/rust/processor/src/processors/token_v2_processor.rs index 35ebdff04..e806e08c2 100644 --- a/rust/processor/src/processors/token_v2_processor.rs +++ b/rust/processor/src/processors/token_v2_processor.rs @@ -287,9 +287,25 @@ fn insert_current_collections_v2_query( diesel::insert_into(schema::current_collections_v2::table) .values(items_to_insert) .on_conflict(collection_id) - .do_nothing(), - None, - ) + .do_update() + .set(( + creator_address.eq(excluded(creator_address)), + collection_name.eq(excluded(collection_name)), + description.eq(excluded(description)), + uri.eq(excluded(uri)), + current_supply.eq(excluded(current_supply)), + max_supply.eq(excluded(max_supply)), + total_minted_v2.eq(excluded(total_minted_v2)), + mutable_description.eq(excluded(mutable_description)), + mutable_uri.eq(excluded(mutable_uri)), + table_handle_v1.eq(excluded(table_handle_v1)), + token_standard.eq(excluded(token_standard)), + last_transaction_version.eq(excluded(last_transaction_version)), + last_transaction_timestamp.eq(excluded(last_transaction_timestamp)), + inserted_at.eq(excluded(inserted_at)), + )), + Some(" WHERE current_collections_v2.last_transaction_version <= excluded.last_transaction_version "), + ) } fn insert_current_token_datas_v2_query( @@ -306,9 +322,18 @@ fn insert_current_token_datas_v2_query( .on_conflict(token_data_id) .do_update() .set(( + collection_id.eq(excluded(collection_id)), + token_name.eq(excluded(token_name)), maximum.eq(excluded(maximum)), supply.eq(excluded(supply)), + largest_property_version_v1.eq(excluded(largest_property_version_v1)), + token_uri.eq(excluded(token_uri)), + description.eq(excluded(description)), + token_properties.eq(excluded(token_properties)), + token_standard.eq(excluded(token_standard)), is_fungible_v2.eq(excluded(is_fungible_v2)), + last_transaction_version.eq(excluded(last_transaction_version)), + last_transaction_timestamp.eq(excluded(last_transaction_timestamp)), inserted_at.eq(excluded(inserted_at)), decimals.eq(excluded(decimals)), )), @@ -330,8 +355,16 @@ fn insert_current_token_ownerships_v2_query( .on_conflict((token_data_id, property_version_v1, owner_address, storage_id)) .do_update() .set(( + amount.eq(excluded(amount)), + table_type_v1.eq(excluded(table_type_v1)), + token_properties_mutated_v1.eq(excluded(token_properties_mutated_v1)), + is_soulbound_v2.eq(excluded(is_soulbound_v2)), + token_standard.eq(excluded(token_standard)), is_fungible_v2.eq(excluded(is_fungible_v2)), + last_transaction_version.eq(excluded(last_transaction_version)), + last_transaction_timestamp.eq(excluded(last_transaction_timestamp)), inserted_at.eq(excluded(inserted_at)), + non_transferrable_by_owner.eq(excluded(non_transferrable_by_owner)), )), Some(" WHERE current_token_ownerships_v2.last_transaction_version <= excluded.last_transaction_version "), ) @@ -351,6 +384,9 @@ fn insert_current_deleted_token_ownerships_v2_query( .on_conflict((token_data_id, property_version_v1, owner_address, storage_id)) .do_update() .set(( + amount.eq(excluded(amount)), + last_transaction_version.eq(excluded(last_transaction_version)), + last_transaction_timestamp.eq(excluded(last_transaction_timestamp)), is_fungible_v2.eq(excluded(is_fungible_v2)), inserted_at.eq(excluded(inserted_at)), )), @@ -391,8 +427,14 @@ fn insert_current_token_v2_metadatas_query( diesel::insert_into(schema::current_token_v2_metadata::table) .values(items_to_insert) .on_conflict((object_address, resource_type)) - .do_nothing(), - None, + .do_update() + .set(( + data.eq(excluded(data)), + state_key_hash.eq(excluded(state_key_hash)), + last_transaction_version.eq(excluded(last_transaction_version)), + inserted_at.eq(excluded(inserted_at)), + )), + Some(" WHERE current_token_v2_metadata.last_transaction_version <= excluded.last_transaction_version "), ) }