Skip to content

Commit 82fd23c

Browse files
committed
refactor
1 parent e9f60c9 commit 82fd23c

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

src/components/valve.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ impl Valve {
4141

4242
let result = this.downloaded - this.finished <= this.cfg.allowed_lag;
4343

44-
info!(
45-
Valve,
46-
format!("should continue download? {result}");
47-
downloaded => this.downloaded,
48-
finished => this.finished,
49-
lag => this.downloaded - this.finished,
50-
allowed_lag => this.cfg.allowed_lag
51-
);
44+
if this.cfg.allowed_lag > 0 {
45+
info!(
46+
Valve,
47+
format!("should continue download? {result}");
48+
downloaded => this.downloaded,
49+
finished => this.finished,
50+
lag => this.downloaded - this.finished,
51+
allowed_lag => this.cfg.allowed_lag
52+
);
53+
}
5254

5355
result
5456
}

src/database/memory_db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl MemoryDb {
123123
}
124124

125125
pub fn clear(&mut self) {
126-
self.0.clear()
126+
self.0 = HashMap::new();
127127
}
128128
}
129129

src/database/mod.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod utils;
77
use crate::common::BlockPtr;
88
use crate::config::DatabaseConfig;
99
use crate::errors::DatabaseError;
10+
use crate::info;
1011
use crate::messages::EntityID;
1112
use crate::messages::EntityType;
1213
use crate::messages::FieldName;
@@ -22,6 +23,7 @@ use memory_db::MemoryDb;
2223
use metrics::DatabaseMetrics;
2324
use prometheus::Registry;
2425
use std::sync::Arc;
26+
use std::time::Instant;
2527
use tokio::sync::Mutex;
2628

2729
pub struct Database {
@@ -257,13 +259,23 @@ impl DatabaseAgent {
257259
.await
258260
}
259261

260-
pub async fn migrate(&self, block_ptr: BlockPtr) -> Result<(), DatabaseError> {
262+
pub async fn commit_data(&self, block_ptr: BlockPtr) -> Result<(), DatabaseError> {
263+
let time = Instant::now();
264+
let block_number = block_ptr.number;
261265
let mut db = self.db.lock().await;
262-
db.migrate_from_mem_to_db(block_ptr).await
266+
db.migrate_from_mem_to_db(block_ptr).await?;
267+
info!(
268+
Database,
269+
"committed to database";
270+
block_number => block_number,
271+
exec_time => format!("{:?}", time.elapsed())
272+
);
273+
Ok(())
263274
}
264275

265-
pub async fn clear_in_memory(&self) -> Result<(), DatabaseError> {
276+
pub async fn flush_cache(&self) -> Result<(), DatabaseError> {
266277
self.db.lock().await.mem.clear();
278+
info!(Database, "flushed entity cache");
267279
Ok(())
268280
}
269281

0 commit comments

Comments
 (0)