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

add property maps indexing to collections v2 #437

Merged
merged 3 commits into from
Jul 8, 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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct CollectionV2 {
pub mutable_description: Option<bool>,
pub mutable_uri: Option<bool>,
pub table_handle_v1: Option<String>,
pub collection_properties: Option<serde_json::Value>,
pub token_standard: String,
pub transaction_timestamp: chrono::NaiveDateTime,
}
Expand All @@ -67,6 +68,7 @@ pub struct CurrentCollectionV2 {
pub mutable_uri: Option<bool>,
pub table_handle_v1: Option<String>,
pub token_standard: String,
pub collection_properties: Option<serde_json::Value>,
pub last_transaction_version: i64,
pub last_transaction_timestamp: chrono::NaiveDateTime,
}
Expand Down Expand Up @@ -104,6 +106,7 @@ impl CollectionV2 {
let (mut current_supply, mut max_supply, mut total_minted_v2) =
(BigDecimal::zero(), None, None);
let (mut mutable_description, mut mutable_uri) = (None, None);
let mut collection_properties = serde_json::Value::Null;
if let Some(object_data) = object_metadatas.get(&resource.address) {
// Getting supply data (prefer fixed supply over unlimited supply although they should never appear at the same time anyway)
let fixed_supply = object_data.fixed_supply.as_ref();
Expand Down Expand Up @@ -143,6 +146,12 @@ impl CollectionV2 {
mutable_description = Some(collection.mutable_description);
mutable_uri = Some(collection.mutable_uri);
}

collection_properties = object_data
.property_map
.as_ref()
.map(|m| m.inner.clone())
.unwrap_or(collection_properties);
} else {
// ObjectCore should not be missing, returning from entire function early
return Ok(None);
Expand All @@ -169,6 +178,7 @@ impl CollectionV2 {
mutable_description,
mutable_uri,
table_handle_v1: None,
collection_properties: Some(collection_properties.clone()),
token_standard: TokenStandard::V2.to_string(),
transaction_timestamp: txn_timestamp,
},
Expand All @@ -185,6 +195,7 @@ impl CollectionV2 {
mutable_uri,
table_handle_v1: None,
token_standard: TokenStandard::V2.to_string(),
collection_properties: Some(collection_properties),
last_transaction_version: txn_version,
last_transaction_timestamp: txn_timestamp,
},
Expand Down Expand Up @@ -282,6 +293,7 @@ impl CollectionV2 {
table_handle_v1: Some(table_handle.clone()),
token_standard: TokenStandard::V1.to_string(),
transaction_timestamp: txn_timestamp,
collection_properties: Some(serde_json::Value::Null),
},
CurrentCollectionV2 {
collection_id,
Expand All @@ -296,6 +308,7 @@ impl CollectionV2 {
mutable_description: Some(collection_data.mutability_config.description),
table_handle_v1: Some(table_handle),
token_standard: TokenStandard::V1.to_string(),
collection_properties: Some(serde_json::Value::Null),
last_transaction_version: txn_version,
last_transaction_timestamp: txn_timestamp,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE current_collections_v2
DROP COLUMN IF EXISTS collection_properties;

ALTER TABLE collections_v2
DROP COLUMN IF EXISTS collection_properties;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE current_collections_v2
ADD COLUMN collection_properties JSONB;

ALTER TABLE collections_v2
ADD COLUMN collection_properties JSONB;
2 changes: 2 additions & 0 deletions rust/processor/src/db/postgres/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ diesel::table! {
token_standard -> Varchar,
transaction_timestamp -> Timestamp,
inserted_at -> Timestamp,
collection_properties -> Nullable<Jsonb>,
}
}

Expand Down Expand Up @@ -364,6 +365,7 @@ diesel::table! {
last_transaction_version -> Int8,
last_transaction_timestamp -> Timestamp,
inserted_at -> Timestamp,
collection_properties -> Nullable<Jsonb>,
}
}

Expand Down
7 changes: 6 additions & 1 deletion rust/processor/src/processors/token_v2_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ fn insert_collections_v2_query(
diesel::insert_into(schema::collections_v2::table)
.values(items_to_insert)
.on_conflict((transaction_version, write_set_change_index))
.do_nothing(),
.do_update()
.set((
collection_properties.eq(excluded(collection_properties)),
inserted_at.eq(excluded(inserted_at)),
)),
None,
)
}
Expand Down Expand Up @@ -354,6 +358,7 @@ fn insert_current_collections_v2_query(
table_handle_v1.eq(excluded(table_handle_v1)),
token_standard.eq(excluded(token_standard)),
last_transaction_version.eq(excluded(last_transaction_version)),
collection_properties.eq(excluded(collection_properties)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to update insert_collections_v2_query so that it backfills the new column

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated!

last_transaction_timestamp.eq(excluded(last_transaction_timestamp)),
inserted_at.eq(excluded(inserted_at)),
)),
Expand Down
Loading