Skip to content

Commit

Permalink
remove push_missing_items_back argument
Browse files Browse the repository at this point in the history
  • Loading branch information
bragov4ik committed Dec 9, 2024
1 parent 5dbcbce commit 9c224a5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
27 changes: 10 additions & 17 deletions stats/stats-server/src/config/read/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,12 @@ impl From<json::layout::Config> for Config {

/// Arranges the items `to_sort` according to order in `layout`.
///
/// `push_missing_items_back`:
/// - if `true`, then items not present in
/// `layout` are placed at the end of the vector in their original
/// relative order.
/// - if `false` - at the beginning with the same logic.
/// Items not present in `layout` are placed at the end of the
/// vector in their original relative order.
pub fn sorted_items_according_to_layout<Item, Key, F>(
to_sort: Vec<Item>,
layout: &[Key],
get_key: F,
push_missing_items_back: bool,
) -> Vec<Item>
where
Key: Ord,
Expand All @@ -53,19 +49,16 @@ where
.enumerate()
.map(|(pos, key)| (key, pos))
.collect();
let mut to_sort_with_new_positions: Vec<_> = to_sort
let mut result: Vec<_> = to_sort
.into_iter()
.map(|item| {
let mut key = assigned_positions.get(get_key(&item)).copied();
if push_missing_items_back {
key.get_or_insert(usize::MAX);
}
(item, key)
let position = assigned_positions
.get(get_key(&item))
.copied()
.unwrap_or(usize::MAX);
(item, position)
})
.collect();
to_sort_with_new_positions.sort_by_key(|p| p.1);
to_sort_with_new_positions
.into_iter()
.map(|p| p.0)
.collect()
result.sort_by_key(|p| p.1);
result.into_iter().map(|p| p.0).collect()
}
1 change: 0 additions & 1 deletion stats/stats-server/src/config/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ impl LineChartCategory {
category_infos_alphabetic_order,
&self.charts_order,
|chart_info| &chart_info.id,
true,
);
proto_v1::LineChartSection {
id: self.id,
Expand Down
8 changes: 2 additions & 6 deletions stats/stats-server/src/read_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,8 @@ impl StatsService for ReadService {
})
})
.collect();
let counters_sorted = sorted_items_according_to_layout(
counters,
&self.charts.counters_layout,
|c| &c.id,
true,
);
let counters_sorted =
sorted_items_according_to_layout(counters, &self.charts.counters_layout, |c| &c.id);
let counters = proto_v1::Counters {
counters: counters_sorted,
};
Expand Down

0 comments on commit 9c224a5

Please sign in to comment.