tldr-node-client icon indicating copy to clipboard operation
tldr-node-client copied to clipboard

Running tldr with a non-existent topic or doing an update causes long freezes

Open sdondley opened this issue 1 year ago • 7 comments

I'm on alpine, installed with npm. If I do tldr blah I see something like this:

✔ Updating...
⠼ Creating index...

It just hangs for like two minutes. Same thing happens when tldr --update is run.

sdondley avatar Jul 23 '24 14:07 sdondley

Yes, this is due to the single threaded nature of tldr. We try to yield in intervals but it's difficult to make the spinner run more smoothly. But it's just due to the addition of the spinner that you "feel" it's stuck. It's just creating the index.

Is there a real bug that you wanted to report?

agnivade avatar Jul 26 '24 03:07 agnivade

So you're saying it's not a bug that if I make a typo or type in a non-existent document I have to open a new terminal shell and or wait two minutes for the program to re-index everything? This isn't just a "feeling" I have. 2 minutes is a long time for the command line to lockup and do nothing.

sdondley avatar Jul 28 '24 16:07 sdondley

Sorry I realize that my earlier post came across as snarky. Wasn't my intention.

if I make a typo or type in a non-existent document I have to open a new terminal shell and or wait two minutes for the program to re-index everything?

You could just cancel the re-indexing. You don't need to wait. The fact that we decide to re-populate the cache if a command isn't found was a design decision based on the fact that the newly entered command might exist in the remote repo, but not in the local cache.

We could, technically add an escape hatch to prevent this behavior. I am open to it. But the core issue here is that indexing takes some time and freezes the UI. And that's not a bug. It's just due to the single threaded design of node.js. I am sure it can be improved. PRs would be most welcome.

agnivade avatar Jul 29 '24 04:07 agnivade

What about re-indexing only if page exists in the remote repo (ping https://raw.githubusercontent.com/tldr-pages/tldr/main/pages.xx/platform/page.md)?

spageektti avatar Jul 29 '24 08:07 spageektti

Sure, a reasonable approach.

agnivade avatar Jul 30 '24 04:07 agnivade

We have been providing a pre-built index for a while upstream at https://github.com/tldr-pages/tldr/releases/latest/download/index.json, would it be possible for the Node client to be adapted to use it?

kbdharun avatar Jul 30 '24 07:07 kbdharun

The client builds its own search index. There's some logic here: https://github.com/tldr-pages/tldr-node-client/blob/main/lib/search.js. Unless we pre-build this entire logic, it might be difficult.

agnivade avatar Jul 30 '24 07:07 agnivade