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

[Spec] Download page index from tldr.sh #6

Open
BrainMaestro opened this issue Dec 6, 2017 · 5 comments
Open

[Spec] Download page index from tldr.sh #6

BrainMaestro opened this issue Dec 6, 2017 · 5 comments

Comments

@BrainMaestro
Copy link
Owner

This will be nontrivial. The JSON file at https://tldr.sh/assets/index.json should be downloaded and stored in the .tldr folder. This file will be the source of truth for finding commands instead of attempting to read a page by making a request or checking the cache. We can find the location of a page by searching through the JSON file. It would probably need to be converted to a format that is easier to query.

@owenvoke
Copy link
Contributor

owenvoke commented Dec 6, 2017

Could use collections for this for easier searching?
https://packagist.org/packages/tightenco/collect

I'm happy to work on this. 👍

@BrainMaestro
Copy link
Owner Author

BrainMaestro commented Dec 6, 2017

I like collections, but i'm not sure exactly how it would help, because the format is

[{"name":"7z","platform":["common"]},{"name":"hg","platform":["common"]}]

which is not easy to work with. I would like to convert it into a map that like

{"7z": {"platform":["common"]}, "hg": {"platform":["common"]}}

This way, searching for items can be done in constant time. This new JSON structure can be persisted to disk as well instead of having to recreate it each time. We can even extend the structure to contain the relative paths to the markdown files. The entire thing will obviously be rebuilt when the cache is refreshed.

@owenvoke
Copy link
Contributor

owenvoke commented Dec 6, 2017

I've done some tests locally with collections, because I was thinking it could check the local index.json against the remote one.

I got everything working with a test Cache class. So I'll push that up, but not make a PR cause it's just for an example.

https://github.com/pxgamer/tldr-php/blob/feature/example-testing/src/Cache.php

@BrainMaestro
Copy link
Owner Author

While that works, this part https://github.com/pxgamer/tldr-php/blob/feature/example-testing/src/Cache.php#L54-L56 is my issue. That operation can be potentially expensive. It's an O(n) search.

@owenvoke
Copy link
Contributor

owenvoke commented Dec 6, 2017

Yeh, that's true. I'll have a look at the remapping like you specified.

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

No branches or pull requests

2 participants