Skip to content

tldr always get data from url without using cache if the platform is empty. #150

Closed
@ramwin

Description

@ramwin

My system: ubuntu 20.04
My tldr version: latest.

In the code:

tldr-python-client/tldr.py

Lines 194 to 204 in daf1ebf

def get_page(command, remote=None, platforms=None, languages=None):
if platforms is None:
platforms = get_platform_list()
if languages is None:
languages = get_language_list()
for platform in platforms:
for language in languages:
if platform is None:
continue
try:
return get_page_for_platform(command, platform, remote, language)

the tldr client will always try to find the command in linux platform first. So if a command is common (like, ls, zip), the tldr command will first try to find cache file only in <cache_dir>/linux/ls.md and since the ls.md is in the <cache_dir>/common/ls.md, not in the <cache_dir>/linux/ls.md, the cache failed.

Then, the client will try to get <remote_url>/linux/ls.md from remote server. and the remote server return 404.

After that, the client will use the platform common and the cache is found.

I suggest change code like this:

for platform in platforms:  # find cache first
    try:
        load_page_from_cache(command, platform, languate)
    except Exception:
        continue
for platform in platforms:  # if failed , get it from server
    try:
        load_page_from_server(command, platform, languate)
    except Exception:
        continue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions