Skip to content

Commit

Permalink
tiny improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyMatt committed May 28, 2024
1 parent b6fd292 commit f0ba829
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
5 changes: 1 addition & 4 deletions src/graph/asynchronous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ impl AsyncGraph {
return Ok(vec![]);
}

Ok(res
.into_iter()
.flat_map(|entry_raw| SlowlogEntry::from_value_vec(entry_raw.into_vec()?))
.collect())
Ok(res.into_iter().flat_map(SlowlogEntry::try_from).collect())
}

/// Resets the slowlog, all query time data will be cleared.
Expand Down
5 changes: 1 addition & 4 deletions src/graph/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ impl SyncGraph {
return Ok(vec![]);
}

Ok(res
.into_iter()
.flat_map(|entry_raw| SlowlogEntry::from_value_vec(entry_raw.into_vec()?))
.collect())
Ok(res.into_iter().flat_map(SlowlogEntry::try_from).collect())
}

/// Resets the slowlog, all query time data will be cleared.
Expand Down
10 changes: 6 additions & 4 deletions src/response/slowlog_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

use crate::{FalkorDBError, FalkorValue};
use anyhow::Result;

/// A slowlog entry, representing one of the N slowest queries in the current log
#[derive(Clone, Debug, PartialEq)]
Expand All @@ -19,9 +18,12 @@ pub struct SlowlogEntry {
pub time_taken: f64,
}

impl SlowlogEntry {
pub(crate) fn from_value_vec(values: Vec<FalkorValue>) -> Result<Self> {
let [timestamp, command, arguments, time_taken] = values
impl TryFrom<FalkorValue> for SlowlogEntry {
type Error = FalkorDBError;

fn try_from(value: FalkorValue) -> std::result::Result<Self, Self::Error> {
let [timestamp, command, arguments, time_taken] = value
.into_vec()?
.try_into()
.map_err(|_| FalkorDBError::ParsingArrayToStructElementCount)?;

Expand Down

0 comments on commit f0ba829

Please sign in to comment.