Skip to content

Commit

Permalink
naming refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Oct 4, 2024
1 parent b12107d commit 9eb9b2a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
14 changes: 10 additions & 4 deletions crates/torii/core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use tracing::{debug, error};

use crate::simple_broker::SimpleBroker;
use crate::types::{
Entity as EntityUpdated, Event as EventEmitted, EventMessage as EventMessageUpdated,
IndexerUpdate, Model as ModelRegistered,
Contract as ContractUpdated, Entity as EntityUpdated, Event as EventEmitted,
EventMessage as EventMessageUpdated, Model as ModelRegistered,
};

pub(crate) const LOG_TARGET: &str = "torii_core::executor";
Expand All @@ -31,7 +31,7 @@ pub enum Argument {

#[derive(Debug, Clone)]
pub enum BrokerMessage {
SetHead(IndexerUpdate),
SetHead(ContractUpdated),
ModelRegistered(ModelRegistered),
EntityUpdated(EntityUpdated),
EventMessageUpdated(EventMessageUpdated),
Expand Down Expand Up @@ -208,7 +208,13 @@ impl<'c> Executor<'c> {
format!("Failed to execute query: {:?}, args: {:?}", statement, arguments)
})?;

self.publish_queue.push(BrokerMessage::SetHead(IndexerUpdate {
sqlx::query("UPDATE contracts SET tps = ? WHERE id = ?")
.bind(tps as i64)
.bind(format!("{:#x}", set_head.contract_address))
.execute(&mut **tx)
.await?;

self.publish_queue.push(BrokerMessage::SetHead(ContractUpdated {
head: set_head.head,
tps,
last_block_timestamp: set_head.last_block_timestamp,
Expand Down
5 changes: 3 additions & 2 deletions crates/torii/core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ pub struct Event {
pub created_at: DateTime<Utc>,
}

#[derive(Debug, Clone)]
pub struct IndexerUpdate {
#[derive(FromRow, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Contract {
pub head: u64,
pub tps: u64,
pub last_block_timestamp: u64,
Expand Down
8 changes: 4 additions & 4 deletions crates/torii/grpc/src/server/subscriptions/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tokio::sync::mpsc::{channel, Receiver, Sender};
use tokio::sync::RwLock;
use torii_core::error::Error;
use torii_core::simple_broker::SimpleBroker;
use torii_core::types::IndexerUpdate;
use torii_core::types::Contract as ContractUpdated;
use tracing::{error, trace};

use crate::proto;
Expand Down Expand Up @@ -67,17 +67,17 @@ impl IndexerManager {
#[allow(missing_debug_implementations)]
pub struct Service {
subs_manager: Arc<IndexerManager>,
simple_broker: Pin<Box<dyn Stream<Item = IndexerUpdate> + Send>>,
simple_broker: Pin<Box<dyn Stream<Item = ContractUpdated> + Send>>,
}

impl Service {
pub fn new(subs_manager: Arc<IndexerManager>) -> Self {
Self { subs_manager, simple_broker: Box::pin(SimpleBroker::<IndexerUpdate>::subscribe()) }
Self { subs_manager, simple_broker: Box::pin(SimpleBroker::<ContractUpdated>::subscribe()) }
}

async fn publish_updates(
subs: Arc<IndexerManager>,
update: &IndexerUpdate,
update: &ContractUpdated,
) -> Result<(), Error> {
let mut closed_stream = Vec::new();

Expand Down

This file was deleted.

3 changes: 3 additions & 0 deletions crates/torii/migrations/20240923155431_tps.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Add last_block_timestamp column for TPS calculation
ALTER TABLE contracts ADD COLUMN last_block_timestamp INTEGER;
ALTER TABLE contracts ADD COLUMN tps INTEGER;

0 comments on commit 9eb9b2a

Please sign in to comment.