Skip to content

Sort crate features by name #1320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/web/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub fn build_features_handler(req: &mut Request) -> IronResult<Response> {
let row = cexpect!(req, rows.get(0));

let mut features = None;
// features enabled by the default feature flag
let mut default_len = 0;

if let Some(raw) = row.get(0) {
Expand All @@ -79,15 +80,22 @@ pub fn build_features_handler(req: &mut Request) -> IronResult<Response> {
fn order_features_and_count_default_len(raw: Vec<Feature>) -> (Vec<Feature>, usize) {
let mut feature_map = get_feature_map(raw);
let mut features = get_tree_structure_from_default(&mut feature_map);
let mut remaining: Vec<_> = feature_map
let remaining: Vec<_> = feature_map
.into_iter()
.map(|(_, feature)| feature)
.collect();
remaining.sort_by_key(|feature| feature.subfeatures.len());

let default_len = features.len();

features.extend(remaining.into_iter().rev());
features.sort_by(|a, b| {
// 'default' feature is special and should always stay on top
if b.name == "default" {
std::cmp::Ordering::Greater
} else {
a.name.partial_cmp(&b.name).unwrap()
}
});
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at first I've tried to simply change the sorting at the SQL level on line 55 but I think this sorting in this function would neutralize it anyway

(features, default_len)
}

Expand Down