-
Notifications
You must be signed in to change notification settings - Fork 154
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
Remove duplicates from file-based history search #741
Conversation
It seems like there may be two ways to do this.
I'm not sure which way is best. One thing that concerns me is what the impact will be filtering this way when there are 10s of thousands of history entries. |
This is the proper solution IMHO... |
The
I feel a bit dumb that I haven't looked at the file "format" for the text based history. For that, it probably makes more sense to not store duplicates. I'll take a look at that this weekend as well.
Reading the history items from the file is probably the performance bottleneck here. Memory-wise, I don't think that this is a serious issue. If you choose to have a history of 1_000_000 items, you probably have a computer that can handle this easily. However, to limit the memory usage in most cases, I have created another commit, that filters the duplicates after filtering by the input. The worst case memory usage is still the same. E.g. if all history items contain an "a" and you filter by "a", the set will have the same size. If there are a lot of duplicates, this might actually save memory. |
I'm kind of in the camp of fixing the problem vs fixing the symptom. The problem (maybe) is that we have dupes in our history. I'm not exactly sure how to fix that myself because I think you'd always want the most recent dupe in the more recent history vs a long way away. Having said that, I'm not sure this is working right as it works with our menus. I'm trying to test with |
89ca9ab
to
fea1afc
Compare
I've read through a lot of the source code and I think that this is a reasonable short term solution to remove the duplicates from the file-based history. If we want to avoid adding duplicates to the history file in the first place, the backend for that has to be architected differently. Since this seems to fall into the scope of #735, I`ll add some of my observations and suggestions there. |
@saep thanks ! this looks great 👍 |
I strongly disagree with the idea of removing duplicates from the history. From a There are multiple reasons to that, the most obvious being backtracing: I want to be able to see what commands I executed in order without any missing. It's especially useful when trying to redo a set of instructions in order. That happened to me multiple times and I don't think it's that rare of a scenario either. So I think duplicates should not be removed from history, only from the fuzzy-finding search. |
@ClementNerma point well made and I understand where you are coming from but I am still leaning towards removing the duplicates... But this shows why we want to give the user the ability to do their own History implementation --- here is yet another example of having removing Duplicates as the Default scenario --- but users like yourself who want to keep the duplicates can easily replace the Default History Trait or something to that effect with your History Trait which keeps the duplicates. Or your history Trait which stores to a database like Sled instead of Sqlite etc... Or whatever other cool History features other developers will come up with that is more useful for their type of scenario. |
It already does not do this... If you type ls three times or version three times in a row it is only shown once.... |
Maybe it would be interesting to see what Nushell's choice would be on that matter, implement it as the default behaviour, and make it configurable for whoever wants to customize it? |
In the sqlite history, if we were only keeping unique commands, i'd want to update the time date stamp each time a duplicate command is executed and ensure our history pulls from the most recent. I don't want to type |
We talked about this today in our meeting (Feb 7th, 2024). This is how we decided that we'd like it to work. Maybe it's what you've already done. I'm not sure.
Example: Here's the items in the history
a. Hitting up with
|
@fdncred I am going to go ahead and close this PR ? Now that you have documented a future PR the next developer can start from a clean slate... In case anyone wants to move forward in the future they can review what you have written.... |
fea1afc
to
dc356e0
Compare
dc356e0
to
19be613
Compare
I've rebased on main and added a test specifying your wanted behavior. For that, I had to move the duplicate tests back to the history module. Since I've removed the call to |
I tested it with |
I've just started using nushell and I'm using
ctrl+r
a lot. I was surprised to see duplicates in the suggestions and I can't think of a good reason why there should be any. It is noisy and it might require additional key presses to select the thing I want. So I took a look at it and created a PR. ❤️