From 2da4039bd27f7307157916a73d2a1d9a889da816 Mon Sep 17 00:00:00 2001 From: Kyle Espinola Date: Sat, 14 Sep 2024 15:41:12 +0200 Subject: [PATCH] refactor: drop exculsion clauses on cl_items to allow for reindexing --- program_transformers/src/bubblegum/db.rs | 47 ++++-------------------- 1 file changed, 7 insertions(+), 40 deletions(-) diff --git a/program_transformers/src/bubblegum/db.rs b/program_transformers/src/bubblegum/db.rs index 2a3d2e2ad..de6f182c1 100644 --- a/program_transformers/src/bubblegum/db.rs +++ b/program_transformers/src/bubblegum/db.rs @@ -2,8 +2,7 @@ use { crate::error::{ProgramTransformerError, ProgramTransformerResult}, das_core::DownloadMetadataInfo, digital_asset_types::dao::{ - asset, asset_authority, asset_creators, asset_data, asset_grouping, backfill_items, - cl_audits_v2, cl_items, + asset, asset_authority, asset_creators, asset_data, asset_grouping, cl_audits_v2, cl_items, sea_orm_active_enums::{ ChainMutability, Instruction, Mutability, OwnerType, RoyaltyTargetType, SpecificationAssetClass, SpecificationVersions, @@ -11,18 +10,18 @@ use { }, mpl_bubblegum::types::{Collection, Creator}, sea_orm::{ - entity::{ActiveValue, ColumnTrait, EntityTrait}, + entity::{ActiveValue, EntityTrait}, prelude::*, - query::{JsonValue, QueryFilter, QuerySelect, QueryTrait}, + query::{JsonValue, QueryTrait}, sea_query::query::OnConflict, ConnectionTrait, DbBackend, TransactionTrait, }, spl_account_compression::events::ChangeLogEventV1, - tracing::{debug, error, info}, + tracing::{debug, error}, }; pub async fn save_changelog_event<'c, T>( - change_log_event: &ChangeLogEventV1, + change_log_event: &ChangeLogEventV2, slot: u64, txn_id: &str, txn: &T, @@ -80,7 +79,7 @@ where }; i += 1; - let mut query = cl_items::Entity::insert(item) + let query = cl_items::Entity::insert(item) .on_conflict( OnConflict::columns([cl_items::Column::Tree, cl_items::Column::NodeIdx]) .update_columns([ @@ -92,7 +91,6 @@ where .to_owned(), ) .build(DbBackend::Postgres); - query.sql = format!("{} WHERE excluded.seq > cl_items.seq", query.sql); txn.execute(query) .await .map_err(|db_err| ProgramTransformerError::StorageWriteError(db_err.to_string()))?; @@ -121,7 +119,7 @@ where cl_audits_v2::Column::LeafIdx, cl_audits_v2::Column::Seq, ]) - .do_nothing() + .update_columns([cl_audits_v2::Column::Tx, cl_audits_v2::Column::Instruction]) .to_owned(), ) .build(DbBackend::Postgres); @@ -132,37 +130,6 @@ where } } - // If and only if the entire path of nodes was inserted into the `cl_items` table, then insert - // a single row into the `backfill_items` table. This way if an incomplete path was inserted - // into `cl_items` due to an error, a gap will be created for the tree and the backfiller will - // fix it. - if i - 1 == depth as i64 { - // See if the tree already exists in the `backfill_items` table. - let rows = backfill_items::Entity::find() - .filter(backfill_items::Column::Tree.eq(tree_id)) - .limit(1) - .all(txn) - .await?; - - // If the tree does not exist in `backfill_items` and the sequence number is greater than 1, - // then we know we will need to backfill the tree from sequence number 1 up to the current - // sequence number. So in this case we set at flag to force checking the tree. - let force_chk = rows.is_empty() && change_log_event.seq > 1; - - info!("Adding to backfill_items table at level {}", i - 1); - let item = backfill_items::ActiveModel { - tree: ActiveValue::Set(tree_id.to_vec()), - seq: ActiveValue::Set(change_log_event.seq as i64), - slot: ActiveValue::Set(slot as i64), - force_chk: ActiveValue::Set(force_chk), - backfilled: ActiveValue::Set(false), - failed: ActiveValue::Set(false), - ..Default::default() - }; - - backfill_items::Entity::insert(item).exec(txn).await?; - } - Ok(()) }