fix: the latest number of regions (#1546)

* fix: the latest number of regions

* fix: unit test
This commit is contained in:
JeremyHi
2023-05-09 10:11:26 +08:00
committed by GitHub
parent b9661818f2
commit 05e6ca1e14

View File

@@ -251,9 +251,9 @@ pub struct StatValue {
}
impl StatValue {
/// Get the region number from stat value.
/// Get the latest number of regions.
pub fn region_num(&self) -> Option<u64> {
for stat in self.stats.iter() {
for stat in self.stats.iter().rev() {
match stat.region_num {
Some(region_num) => return Some(region_num),
None => continue,
@@ -402,7 +402,7 @@ mod tests {
],
};
let region_num = stat_val.region_num().unwrap();
assert_eq!(1, region_num);
assert_eq!(2, region_num);
}
#[test]