Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
emmazzz committed Jun 22, 2024
1 parent 27b48ad commit f9a5e88
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- TODO: modify queries in indexer reader to take advantage of the new indices
CREATE TABLE events
(
tx_sequence_number BIGINT NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@ CREATE TABLE event_struct_name
(
package BYTEA NOT NULL,
module TEXT NOT NULL,
type_name TEXT NOT NULL,
type_name TEXT NOT NULL,
tx_sequence_number BIGINT NOT NULL,
event_sequence_number BIGINT NOT NULL,
sender BYTEA NOT NULL,
PRIMARY KEY(package, module, type_name, tx_sequence_number, event_sequence_number)
);
CREATE INDEX event_struct_name_sender ON event_struct_name (sender, package, module, type_name, tx_sequence_number, event_sequence_number);

CREATE TABLE event_struct_type
CREATE TABLE event_struct_instantiation
(
package BYTEA NOT NULL,
module TEXT NOT NULL,
full_name TEXT NOT NULL,
type_instantiation TEXT NOT NULL,
tx_sequence_number BIGINT NOT NULL,
event_sequence_number BIGINT NOT NULL,
sender BYTEA NOT NULL,
PRIMARY KEY(package, module, full_name, tx_sequence_number, event_sequence_number)
PRIMARY KEY(package, module, type_instantiation, tx_sequence_number, event_sequence_number)
);
CREATE INDEX event_struct_type_sender ON event_struct_type (sender, package, module, full_name, tx_sequence_number, event_sequence_number);
CREATE INDEX event_struct_instantiation_sender ON event_struct_instantiation (sender, package, module, type_instantiation, tx_sequence_number, event_sequence_number);

CREATE TABLE event_senders
(
Expand Down
16 changes: 8 additions & 8 deletions crates/sui-indexer/src/models/event_indices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

use crate::{
schema::{
event_emit_module, event_emit_package, event_senders, event_struct_module,
event_struct_name, event_struct_package, event_struct_type,
event_emit_module, event_emit_package, event_senders, event_struct_instantiation,
event_struct_module, event_struct_name, event_struct_package,
},
types::EventIndex,
};
Expand Down Expand Up @@ -68,13 +68,13 @@ pub struct StoredEventStructName {
}

#[derive(Queryable, Insertable, Selectable, Debug, Clone, Default)]
#[diesel(table_name = event_struct_type)]
pub struct StoredEventStructType {
#[diesel(table_name = event_struct_instantiation)]
pub struct StoredEventStructInstantiation {
pub tx_sequence_number: i64,
pub event_sequence_number: i64,
pub package: Vec<u8>,
pub module: String,
pub full_name: String,
pub type_instantiation: String,
pub sender: Vec<u8>,
}

Expand All @@ -88,7 +88,7 @@ impl EventIndex {
StoredEventStructPackage,
StoredEventStructModule,
StoredEventStructName,
StoredEventStructType,
StoredEventStructInstantiation,
) {
let tx_sequence_number = self.tx_sequence_number as i64;
let event_sequence_number = self.event_sequence_number as i64;
Expand Down Expand Up @@ -132,12 +132,12 @@ impl EventIndex {
type_name: self.type_name.clone(),
sender: self.sender.to_vec(),
},
StoredEventStructType {
StoredEventStructInstantiation {
tx_sequence_number,
event_sequence_number,
package: self.type_package.to_vec(),
module: self.type_module.clone(),
full_name: self.full_type_name.clone(),
type_instantiation: self.type_instantiation.clone(),
sender: self.sender.to_vec(),
},
)
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-indexer/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ mod inner {
pub use crate::schema::pg::event_emit_module;
pub use crate::schema::pg::event_emit_package;
pub use crate::schema::pg::event_senders;
pub use crate::schema::pg::event_struct_instantiation;
pub use crate::schema::pg::event_struct_module;
pub use crate::schema::pg::event_struct_name;
pub use crate::schema::pg::event_struct_package;
pub use crate::schema::pg::event_struct_type;
pub use crate::schema::pg::events;
pub use crate::schema::pg::objects;
pub use crate::schema::pg::objects_history;
Expand Down Expand Up @@ -67,10 +67,10 @@ pub use inner::epochs;
pub use inner::event_emit_module;
pub use inner::event_emit_package;
pub use inner::event_senders;
pub use inner::event_struct_instantiation;
pub use inner::event_struct_module;
pub use inner::event_struct_name;
pub use inner::event_struct_package;
pub use inner::event_struct_type;
pub use inner::events;
pub use inner::objects;
pub use inner::objects_history;
Expand Down
27 changes: 18 additions & 9 deletions crates/sui-indexer/src/schema/pg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,48 +86,48 @@ diesel::table! {
}

diesel::table! {
event_struct_module (package, module, tx_sequence_number, event_sequence_number) {
event_struct_instantiation (package, module, type_instantiation, tx_sequence_number, event_sequence_number) {
package -> Bytea,
module -> Text,
type_instantiation -> Text,
tx_sequence_number -> Int8,
event_sequence_number -> Int8,
sender -> Bytea,
}
}

diesel::table! {
event_struct_name (package, module, type_name, tx_sequence_number, event_sequence_number) {
event_struct_module (package, module, tx_sequence_number, event_sequence_number) {
package -> Bytea,
module -> Text,
type_name -> Text,
tx_sequence_number -> Int8,
event_sequence_number -> Int8,
sender -> Bytea,
}
}

diesel::table! {
event_struct_package (package, tx_sequence_number, event_sequence_number) {
event_struct_name (package, module, type_name, tx_sequence_number, event_sequence_number) {
package -> Bytea,
module -> Text,
type_name -> Text,
tx_sequence_number -> Int8,
event_sequence_number -> Int8,
sender -> Bytea,
}
}

diesel::table! {
event_struct_type (package, module, full_name, tx_sequence_number, event_sequence_number) {
event_struct_package (package, tx_sequence_number, event_sequence_number) {
package -> Bytea,
module -> Text,
full_name -> Text,
tx_sequence_number -> Int8,
event_sequence_number -> Int8,
sender -> Bytea,
}
}

diesel::table! {
events (tx_sequence_number, event_sequence_number, checkpoint_sequence_number) {
events (tx_sequence_number, event_sequence_number) {
tx_sequence_number -> Int8,
event_sequence_number -> Int8,
transaction_digest -> Bytea,
Expand All @@ -145,7 +145,7 @@ diesel::table! {
}

diesel::table! {
events_partition_0 (tx_sequence_number, event_sequence_number, checkpoint_sequence_number) {
events_partition_0 (tx_sequence_number, event_sequence_number) {
tx_sequence_number -> Int8,
event_sequence_number -> Int8,
transaction_digest -> Bytea,
Expand Down Expand Up @@ -382,6 +382,13 @@ macro_rules! for_all_tables {
checkpoints,
display,
epochs,
event_emit_module,
event_emit_package,
event_senders,
event_struct_instantiation,
event_struct_module,
event_struct_name,
event_struct_package,
events,
events_partition_0,
objects,
Expand All @@ -398,11 +405,13 @@ macro_rules! for_all_tables {
tx_changed_objects,
tx_digests,
tx_input_objects,
tx_kinds,
tx_recipients,
tx_senders
);
};
}

pub use for_all_tables;

for_all_tables!(diesel::allow_tables_to_appear_in_same_query);
16 changes: 8 additions & 8 deletions crates/sui-indexer/src/store/pg_indexer_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ use crate::models::transactions::StoredTransaction;
use crate::schema::tx_kinds;
use crate::schema::{
checkpoints, display, epochs, event_emit_module, event_emit_package, event_senders,
event_struct_module, event_struct_name, event_struct_package, event_struct_type, events,
objects, objects_history, objects_snapshot, objects_version, packages, transactions,
event_struct_instantiation, event_struct_module, event_struct_name, event_struct_package,
events, objects, objects_history, objects_snapshot, objects_version, packages, transactions,
tx_calls_fun, tx_calls_mod, tx_calls_pkg, tx_changed_objects, tx_digests, tx_input_objects,
tx_recipients, tx_senders,
};
Expand Down Expand Up @@ -719,7 +719,7 @@ impl<T: R2D2Connection + 'static> PgIndexerStore<T> {
event_struct_packages,
event_struct_modules,
event_struct_names,
event_struct_types,
event_struct_instantiations,
) = indices.into_iter().map(|i| i.split()).fold(
(
Vec::new(),
Expand All @@ -737,7 +737,7 @@ impl<T: R2D2Connection + 'static> PgIndexerStore<T> {
mut event_struct_packages,
mut event_struct_modules,
mut event_struct_names,
mut event_struct_types,
mut event_struct_instantiations,
),
index| {
event_emit_packages.push(index.0);
Expand All @@ -746,15 +746,15 @@ impl<T: R2D2Connection + 'static> PgIndexerStore<T> {
event_struct_packages.push(index.3);
event_struct_modules.push(index.4);
event_struct_names.push(index.5);
event_struct_types.push(index.6);
event_struct_instantiations.push(index.6);
(
event_emit_packages,
event_emit_modules,
event_senders,
event_struct_packages,
event_struct_modules,
event_struct_names,
event_struct_types,
event_struct_instantiations,
)
},
);
Expand Down Expand Up @@ -807,8 +807,8 @@ impl<T: R2D2Connection + 'static> PgIndexerStore<T> {

futures.push(self.spawn_blocking_task(move |this| {
persist_chunk_into_table!(
event_struct_type::table,
event_struct_types,
event_struct_instantiation::table,
event_struct_instantiations,
&this.blocking_cp
)
}));
Expand Down
15 changes: 8 additions & 7 deletions crates/sui-indexer/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ pub struct EventIndex {
pub type_module: String,
/// Struct name of the event, without type parameters.
pub type_name: String,
/// Struct name of the event, with type parameters, if any.
pub full_type_name: String,
/// Type instantiation of the event, with type name and type parameters, if any.
pub type_instantiation: String,
}

impl EventIndex {
Expand All @@ -242,10 +242,11 @@ impl EventIndex {
event_sequence_number: u64,
event: &sui_types::event::Event,
) -> Self {
let full_type_name = regex::Regex::new(r"^[^:]+::[^:]+::(?<name>\w+)")
.unwrap()
.captures(&event.type_.to_canonical_string(/* with_prefix */ true))
.unwrap()["name"]
let type_instantiation = event
.type_
.to_canonical_string(/* with_prefix */ true)
.splitn(3, "::")
.collect::<Vec<_>>()[2]
.to_string();
Self {
tx_sequence_number,
Expand All @@ -256,7 +257,7 @@ impl EventIndex {
type_package: event.type_.address.into(),
type_module: event.type_.module.to_string(),
type_name: event.type_.name.to_string(),
full_type_name,
type_instantiation,
}
}
}
Expand Down

0 comments on commit f9a5e88

Please sign in to comment.