Skip to content

Commit

Permalink
Truncate histories when length exceeds 10 (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyu08 committed Jun 10, 2024
1 parent e59cfe6 commit ece58b8
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions src/model/histories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ impl History {
let mut executed_targets = self.executed_targets.clone();
executed_targets.retain(|t| *t != executed_target);
executed_targets.insert(0, executed_target.clone());
// const MAX_LENGTH: usize = 10;
// if executed_targets.len() > MAX_LENGTH {
// executed_targets.truncate(MAX_LENGTH);
// }

const MAX_LENGTH: usize = 10;
if MAX_LENGTH < executed_targets.len() {
executed_targets.truncate(MAX_LENGTH);
}

Self {
path: self.path.clone(),
Expand Down Expand Up @@ -364,6 +365,40 @@ mod test {
],
},
},
Case {
title: "Truncate when length exceeds 10",
appending_target: "history11",
history: History {
path: path.clone(),
executed_targets: vec![
"history0".to_string(),
"history1".to_string(),
"history2".to_string(),
"history3".to_string(),
"history4".to_string(),
"history5".to_string(),
"history6".to_string(),
"history7".to_string(),
"history8".to_string(),
"history9".to_string(),
],
},
expect: History {
path: path.clone(),
executed_targets: vec![
"history11".to_string(),
"history0".to_string(),
"history1".to_string(),
"history2".to_string(),
"history3".to_string(),
"history4".to_string(),
"history5".to_string(),
"history6".to_string(),
"history7".to_string(),
"history8".to_string(),
],
},
},
];

for case in cases {
Expand Down

0 comments on commit ece58b8

Please sign in to comment.