Skip to content
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

Pagination by category assigns post to wrong category #932

Open
deep110 opened this issue Nov 2, 2021 · 2 comments
Open

Pagination by category assigns post to wrong category #932

deep110 opened this issue Nov 2, 2021 · 2 comments
Labels
bug Not as expected

Comments

@deep110
Copy link

deep110 commented Nov 2, 2021

When creating the list of categories and assigning posts to it before pagination, wrong category is chosen because of sort.

Code can be found in categories.rs in parse_categories_list
Snippet:

let mut cur_cat = if let Ok(idx) = parent.sub_cats.binary_search_by(|c| {
            compare_category_path(
                c.cat_path.iter().map(|v| v.as_view()),
                cat_full_path.iter().copied(),
            )
        }) {
            &mut parent.sub_cats[idx]
        } else {
            let last_idx = parent.sub_cats.len();
            parent
                .sub_cats
                .push(Category::with_path(cat_full_path.into_iter()));
            // need to sort for binary_search_by
            parent.sub_cats.sort_by(|c1, c2| {
                compare_category_path(
                    c1.cat_path.iter().map(|v| v.as_view()),
                    c2.cat_path.iter().map(|v| v.as_view()),
                )
            });
            &mut parent.sub_cats[last_idx]
        };

Here if order is changed because of sorting then last_idx will return the wrong category.

@epage
Copy link
Member

epage commented Nov 7, 2021

Not good. Thanks for reporting this!

@epage epage added the bug Not as expected label Nov 7, 2021
@yabozdar
Copy link

Has this been resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not as expected
Projects
None yet
Development

No branches or pull requests

3 participants