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

Fix the ordering of categories after application restart #689

Closed
soarpasser opened this issue Aug 31, 2022 · 10 comments
Closed

Fix the ordering of categories after application restart #689

soarpasser opened this issue Aug 31, 2022 · 10 comments

Comments

@soarpasser
Copy link

Currently LR randomizes the display order of a user's archive categories every time the application restarts, see:
Before restart
image
After restart
image

Same goes for the "add to category" dropdown menu whenever you right click an archive, and the dropdown list order in the "modify categories" tab.

This can be a bit of an annoyance in some cases especially for users with OCD (lol).
Pinning the categories one by one in the "modify categories" tab does not work since pinned categories go back to being unpinned after LR restarts as well. Not sure if that is intended behavior.

Either way, it would be neat to at least let the user arrange the ordering of categories and save them.

@Difegue
Copy link
Owner

Difegue commented Sep 6, 2022

The order of categories shouldn't be random: Recently used categories should show up first, preceded by pinned ones.
If you pin everything, I think the order then becomes alphabetical? Not sure.

Pinned categories shouldn't reset after a restart though, are you sure about this? (As in, they don't show up as pinned in the categories configuration screen?)

@soarpasser
Copy link
Author

soarpasser commented Sep 7, 2022

The order of categories shouldn't be random: Recently used categories should show up first, preceded by pinned ones. If you pin everything, I think the order then becomes alphabetical? Not sure.

But apparently they are - see the screenshots here for a before/after comparison.
image
after a restart -
image

Also regarding "Recently used categories should show up first, preceded by pinned ones." - it would be nice to have it so that the order is fixed, instead of automatically being ordered by the most recent category being used.

Pinned categories shouldn't reset after a restart though, are you sure about this? (As in, they don't show up as pinned in the categories configuration screen?)

Positive. After I pin the categories in the "modify categories" tab using this checkbox and restart the app, the previously pinned category goes back to being unpinned.
image

@Difegue
Copy link
Owner

Difegue commented Dec 16, 2022

After a bit more sleuthing, I believe this problem was caused by search cache warm at application boot, which used to do a search for all categories in order to "prep" them -- Which would update their recently used date. 🙄

Cache warm jobs have been entirely removed, so I suspect this shouldn't happen anymore. Letting open for now just in case tho

@soarpasser
Copy link
Author

After a bit more sleuthing, I believe this problem was caused by search cache warm at application boot, which used to do a search for all categories in order to "prep" them -- Which would update their recently used date. 🙄

Cache warm jobs have been entirely removed, so I suspect this shouldn't happen anymore. Letting open for now just in case tho

Leaving this at Feb. 2023 and 0.8.81, I can confirm that this issue is still present. The behavior of LR is still the exact same as I've shown previously, but I won't post screenshots here since censoring all my stuff takes too much time. Still, might need to look into this further.

@cazendium
Copy link

@soarpasser I was under the impression that categories did not have a sort order and just added from right to left.

Screenshot 2023-11-02 at 9 30 47 PM

I was able to have it sort alphabetically from A-Z for pinned categories (in pink outlines), then A-Z for other categories. Both left to right, as shown in my screenshot above.

As for the categories listed in the context menu, I know what you mean by the ordering getting shuffled after restart. It doesn't shuffle if I just terminate LANraragi, only when the redis-server stops. I'm trying to change it there as well.

@Difegue are the categories just randomly taken on boot as just hashes without any sorting? Sorry, I don't know anything about Perl, but interested in fixing this myself.

@Difegue
Copy link
Owner

Difegue commented Nov 5, 2023

@cazendium Conveniently, the sorting code does not use any Perl at all! 😛 Sorting is done clientside based on pinned + last used time.

See the code here:

Index.loadCategories = function () {

@cazendium
Copy link

@Difegue that’s true! I should’ve meant it’s lacking one in Perl, specifically in the Model > Category.pm 🤓

sub get_static_category_list() {

I added a sort before returning @categories in the .pm, which now sorts my context menu for categories in alphabetical order.

Isn’t it more preferable to sort things from A-Z especially when categories get too large?

@cazendium
Copy link

@Difegue @soarpasser the following code below sorts my categories above the search bar alphabetically and in the context menu. But I noticed the redis-server process needs to be stopped too to notice the effects change in the context menu.

index.js

Index.loadCategories = function () {
    Server.callAPI("/api/categories", "GET", null, "Couldn't load categories",
        (data) => {
            data.sort((b, a) => a.name > b.name);
            data.sort((a, b) => a.pinned < b.pinned);

Model Category.pm

sub get_category_list {

    my $redis = LANraragi::Model::Config->get_redis;

    my @cats = $redis->keys('SET_??????????');

    my @result;
    foreach my $key (@cats) {
        my %data = get_category($key);
        push( @result, \%data );
    }

    @result = sort { $a->{name} cmp $b->{name} } @result;

    return @result;
}

sub get_static_category_list() {

    my @categories = get_category_list;

    @categories = grep { %$_{"search"} eq "" } @categories;

    @categories = sort { $a->{name} cmp $b->{name} } @categories;

    return @categories;
}

@Difegue
Copy link
Owner

Difegue commented Nov 6, 2023

My initial thinking behind sorting by last_used time was that if you use a specific category a bunch it'd float up naturally instead of making you hunt in the dropdown -- But if it's buggy/changes too often, we might as well just sort alphabetically and make users rely on pinning.

Could you make a PR with those changes?

@yushizui
Copy link

My initial thinking behind sorting by last_used time was that if you use a specific category a bunch it'd float up naturally instead of making you hunt in the dropdown -- But if it's buggy/changes too often, we might as well just sort alphabetically and make users rely on pinning.

Could you make a PR with those changes?

There seems to be an error in the category sorting after the update. It does not seem to be sorted according to the alphabetical order mentioned above, and the pinning category seems to be invalid. I don’t know if it has something to do with the use of Chinese.

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

No branches or pull requests

4 participants