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

Only download cache for system languages and English #420

Merged
merged 6 commits into from
Oct 24, 2023
Merged

Only download cache for system languages and English #420

merged 6 commits into from
Oct 24, 2023

Conversation

vivekjoshi556
Copy link
Contributor

@vivekjoshi556 vivekjoshi556 commented Oct 4, 2023

Description

Fixes #419
The task at hand was to update the client so that it would only download the zip files for languages that were supported by the user system. In any case, files in english should be downloaded to act as backup.

Explanation of Solution

  • While doing this I realized that the unzip library being used was causing issue as it was emitting the close event on extractor twice and because of it the extraction wasn't completing and some of the files were not getting extracted. Trying to resolve it I saw similiar issues on the official repo and the issue wasn't resolved. So I decided to change the npm package to unzip.
  • It uses both ll & cc to download the correct zip file whenever possible.
  • Is there a way to determine which languages have different version available (like pt has pt_BR, pt_PT), right now I have hard-coded the values in util.js and it will need to be updated in case other versions for other languages are added.

Checklist

Please review this checklist before submitting a pull request.

  • Code compiles correctly
  • Created tests, if possible
  • All tests passing (npm run test:all)
  • Extended the README / documentation, if necessary

@agnivade
Copy link
Member

agnivade commented Oct 5, 2023

Can we add some tests please?

@vivekjoshi556
Copy link
Contributor Author

vivekjoshi556 commented Oct 5, 2023

Can we add some tests please?

@agnivade Sure I'll add the tests
Can you please help me with the failing job in the workflow? All the jobs passed when I made the first commit before the PR, but now one of them is failing. It happened in the repo I forked and when I tried to run the job again alone it passed.

All passed again. 🤔

@kbdharun
Copy link
Member

kbdharun commented Oct 5, 2023

Btw, @vivekjoshi556

Workflow requiring approval before running is enabled for first time contributors so that maintainers can review the code before running the action. (This is to minimize multiple failed runs). After this PR is merged, in future the workflow will run by default for you (without requiring approval).

All passed again. 🤔

The reason for it to pass was that I approved your action run an hour ago when you made the comment.

@vivekjoshi556
Copy link
Contributor Author

Workflow requiring approval before running is enabled for first time contributors so that maintainers can review the code before running the action. (This is to minimize multiple failed runs). After this PR is merged, in future the workflow will run by default for you (without requiring approval).

I understand they require approval. I was talking about the last time the jobs ran for my changes.
Actions run link.
In this run the job for ubuntu-latest, 20.x failed. All others passed.

@kbdharun
Copy link
Member

kbdharun commented Oct 5, 2023

I understand they require approval. I was talking about the last time the jobs ran for my changes.
Actions run link.
In this run the job for ubuntu-latest, 20.x failed. All others passed.

Oh, it is possible that the action run was cancelled as it reached 6 hours limit (default for action runs in GitHub's runners).

@vivekjoshi556 vivekjoshi556 marked this pull request as draft October 7, 2023 12:17
@vivekjoshi556 vivekjoshi556 marked this pull request as ready for review October 8, 2023 17:48
@vivekjoshi556
Copy link
Contributor Author

vivekjoshi556 commented Oct 9, 2023

@kbdharun & @agnivade please check this PR & let me know if anything else needs to be updated.

lib/cache.js Outdated Show resolved Hide resolved
lib/cache.js Outdated Show resolved Hide resolved
lib/config.js Outdated Show resolved Hide resolved
lib/config.js Outdated Show resolved Hide resolved
lib/remote.js Outdated Show resolved Hide resolved
test/remote.spec.js Outdated Show resolved Hide resolved
test/remote.spec.js Outdated Show resolved Hide resolved
config.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@vivekjoshi556
Copy link
Contributor Author

@MasterOdin I am done with the mentioned changes. Please review the PR.

@kbdharun kbdharun added the hacktoberfest-accepted PRs which are eligible for hacktoberfest but won't get merged before 31st label Oct 24, 2023
@MasterOdin MasterOdin changed the title Fix: Download Only the files for Required Language And English as Backup | Changed the package for Unzipping Only download cache for system languages and english Oct 24, 2023
Comment on lines +11 to +15
// If the lang is english then keep the url simple, otherwise add language.
const suffix = (lang === 'en' ? '' : '.' + lang);
const url = config.get().repositoryBase + suffix + '.zip';
const folderName = path.join(loc, 'pages' + suffix);
const REQUEST_TIMEOUT = 10000;
Copy link
Member

@kbdharun kbdharun Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding this, we recently added support for the English archive in the same format tldr-pages-en.zip (after a request from tealdeer's maintainer). Can it be implemented here instead? (This will officially land in the upcoming client spec 2.1)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure should be easy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be noted that only the archive name should be generalized here, while still leaving in place that the english archive is extracted to the pages directory. Changing that behavior is a much larger one, which should be done in a separate PR that's focused purely on that, as will also have to take into account backwards compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, won't it be better to handle this entirely in the same (other) PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say so, but not sure how much @kbdharun wants to see the archive name changed here. The old zip will continue to work anyway for the time being that it's not exactly urgent to make that change either.

@kbdharun kbdharun changed the title Only download cache for system languages and english Only download cache for system languages and English Oct 24, 2023
@kbdharun
Copy link
Member

kbdharun commented Oct 24, 2023

I guess this PR can be merged first, then I will rebase mine with this.

@MasterOdin MasterOdin merged commit d3f0309 into tldr-pages:main Oct 24, 2023
18 checks passed
@vivekjoshi556 vivekjoshi556 deleted the issue_419 branch October 24, 2023 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted PRs which are eligible for hacktoberfest but won't get merged before 31st
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fetch individual translation archives for cache based on the environment variable configuration
4 participants