Skip to content

Commit

Permalink
chore: fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
keroro520 committed Jan 6, 2025
1 parent e4c344d commit fc46298
Showing 1 changed file with 34 additions and 39 deletions.
73 changes: 34 additions & 39 deletions taskdb/src/redis_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl RedisTaskDb {
} else {
error!("Failed to deserialize TaskProvingStatusRecords");
Err(RedisDbError::TaskManager(
format!("Failed to deserialize TaskProvingStatusRecords").to_owned(),
"Failed to deserialize TaskProvingStatusRecords".to_string(),
))
}
}
Expand Down Expand Up @@ -302,7 +302,7 @@ impl RedisTaskDb {
key: &AggregationTaskDescriptor,
new_status: TaskProvingStatus,
) -> RedisDbResult<()> {
let old_value = self.query_aggregation_task(key.into()).unwrap_or_default();
let old_value = self.query_aggregation_task(key).unwrap_or_default();
let mut records = match old_value {
Some(v) => v,
None => {
Expand Down Expand Up @@ -450,11 +450,15 @@ impl RedisTaskDb {
) {
(Ok(desc), _) => {
let status = self.query_proof_task_latest_status(&desc)?;
status.map(|s| kvs.push((TaskDescriptor::SingleProof(desc), s.0)));
if let Some(s) = status {
kvs.push((TaskDescriptor::SingleProof(desc), s.0))
}
}
(_, Ok(desc)) => {
let status = self.query_aggregation_task_latest_status(&desc)?;
status.map(|s| kvs.push((TaskDescriptor::Aggregation(desc), s.0)));
if let Some(s) = status {
kvs.push((TaskDescriptor::Aggregation(desc), s.0))
}
}
_ => (),
}
Expand Down Expand Up @@ -571,11 +575,8 @@ impl RedisTaskDb {
fn prune_aggregation(&mut self) -> RedisDbResult<()> {
let keys: Vec<Value> = self.get_conn()?.keys("*").map_err(RedisDbError::RedisDb)?;
for key in keys.iter() {
match AggregationTaskDescriptor::from_redis_value(key) {
Ok(desc) => {
self.delete_redis(&desc)?;
}
_ => (),
if let Ok(desc) = AggregationTaskDescriptor::from_redis_value(key) {
self.delete_redis(&desc)?;
}
}
Ok(())
Expand All @@ -585,21 +586,18 @@ impl RedisTaskDb {
let mut kvs: Vec<AggregationTaskReport> = Vec::new();
let keys: Vec<Value> = self.get_conn()?.keys("*").map_err(RedisDbError::RedisDb)?;
for key in keys.iter() {
match AggregationTaskDescriptor::from_redis_value(key) {
Ok(desc) => {
let status = self.query_aggregation_task_latest_status(&desc)?;
status.map(|s| {
kvs.push((
AggregationOnlyRequest {
aggregation_ids: desc.aggregation_ids,
proof_type: desc.proof_type,
..Default::default()
},
s.0,
))
});
if let Ok(desc) = AggregationTaskDescriptor::from_redis_value(key) {
let status = self.query_aggregation_task_latest_status(&desc)?;
if let Some(s) = status {
kvs.push((
AggregationOnlyRequest {
aggregation_ids: desc.aggregation_ids,
proof_type: desc.proof_type,
..Default::default()
},
s.0,
));
}
_ => (),
}
}
Ok(kvs)
Expand Down Expand Up @@ -631,12 +629,11 @@ impl RedisTaskDb {
let mut kvs = Vec::new();
let keys: Vec<Value> = self.get_conn()?.keys("*").map_err(RedisDbError::RedisDb)?;
for key in keys.iter() {
match TaskIdDescriptor::from_redis_value(key) {
Ok(desc) => {
let status = self.query_redis(&desc)?;
status.map(|s| kvs.push((desc.0, s)));
if let Ok(desc) = TaskIdDescriptor::from_redis_value(key) {
let status = self.query_redis(&desc)?;
if let Some(s) = status {
kvs.push((desc.0, s));
}
_ => (),
}
}
Ok(kvs)
Expand All @@ -645,11 +642,8 @@ impl RedisTaskDb {
fn prune_stored_ids(&mut self) -> RedisDbResult<()> {
let keys: Vec<Value> = self.get_conn()?.keys("*").map_err(RedisDbError::RedisDb)?;
for key in keys.iter() {
match TaskIdDescriptor::from_redis_value(key) {
Ok(desc) => {
self.delete_redis(&desc)?;
}
_ => (),
if let Ok(desc) = TaskIdDescriptor::from_redis_value(key) {
self.delete_redis(&desc)?;
}
}
Ok(())
Expand Down Expand Up @@ -687,14 +681,13 @@ impl TaskManager for RedisTaskManager {
static mut REDIS_DB: Option<Arc<Mutex<RedisTaskDb>>> = None;
INIT.call_once(|| {
unsafe {
REDIS_DB = Some(Arc::new(Mutex::new({
let db = RedisTaskDb::new(RedisConfig {
REDIS_DB = Some(Arc::new(Mutex::new(
RedisTaskDb::new(RedisConfig {
url: opts.redis_url.clone(),
ttl: opts.redis_ttl.clone(),
ttl: opts.redis_ttl,
})
.unwrap();
db
})))
.unwrap(),
)))
};
});
Self {
Expand Down Expand Up @@ -848,6 +841,7 @@ mod tests {
blockhash: B256::default(),
proof_system: ProofType::Native,
prover: "0x1234".to_owned(),
image_id: None,
};
db.enqueue_task(&params).expect("enqueue task failed");
let status = db.get_task_proving_status(&params);
Expand All @@ -867,6 +861,7 @@ mod tests {
blockhash: B256::default(),
proof_system: ProofType::Native,
prover: "0x1234".to_owned(),
image_id: None,
};
db.enqueue_task(&params).expect("enqueue task failed");
let status = db.get_task_proving_status(&params);
Expand Down

0 comments on commit fc46298

Please sign in to comment.