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

Consume new ghtutorial route when loading tutorials from github #10217

Merged
merged 8 commits into from
Oct 24, 2024

Conversation

riknoll
Copy link
Member

@riknoll riknoll commented Oct 7, 2024

This consumes the newly proposed /api/ghtutorial/ endpoint. Opening as a draft PR because this endpoint isn't actually released yet.

When loading a tutorial from github, this takes the response from /api/ghtutorial/ and uses it to populate all of the caches that we maintain in indexeddb. The rest of the markdown loading pipeline is unchanged, the requests it makes simply hit the cache instead of actually making requests to the backend.

This PR also makes it so that we now cache the latest versions of github repos inside indexeddb just like we do everything else. Unlike the other things we cache, the entries for latest versions expire after an hour. I might end up increasing this period, though, since that isn't very much time at all.

I also added a skipgithubcache=1 query parameter that bypasses all of our local github repo caches to make it easier for content creators to verify their changes.

also tacked on an unrelated change making it so that the saveblocks query param is now case insensitive and accepts saveasblocks since I always accidentally try that first.

@riknoll riknoll requested a review from a team October 7, 2024 17:51
Copy link
Contributor

@eanders-ms eanders-ms left a comment

Choose a reason for hiding this comment

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

Looks good

@riknoll
Copy link
Member Author

riknoll commented Oct 17, 2024

updated with the changes I made to the API route. this now also works with tutorials in the docs folder of targets, uses etags, and proxies requests through the CDN.

here's an upload target you can use to test (micro:bit):

https://makecode.microbit.org/app/de79fa186a7b3225ed5aeb161ea70ec7796af70e-ac898cc414

and here's a URL that includes a docs tutorial that has a GitHub dependency:

https://makecode.microbit.org/app/de79fa186a7b3225ed5aeb161ea70ec7796af70e-ac898cc414?nocdn=1#tutorial:/projects/micro-coin

the ?nocdn=1 is a new query param i added to bypass the CDN. required for this example because the CDN hits our production backend which does not have the new API deployed yet. I recommend opening the tutorial link in an incognito window to make sure you aren't hitting any local caches

@riknoll riknoll marked this pull request as ready for review October 23, 2024 22:05
@riknoll
Copy link
Member Author

riknoll commented Oct 23, 2024

@microsoft/makecode-engineers this is now ready for review! here is an updated upload target:

https://makecode.microbit.org/app/36c4b10f729c193f650f763ba2e37a23adefdd90-bcbbdbd05c

@@ -252,6 +252,14 @@ class FileGithubDb implements pxt.github.IGithubDb {
loadPackageAsync(repopath: string, tag: string): Promise<pxt.github.CachedPackage> {
return this.loadAsync(repopath, tag, "pkg", (r, t) => this.db.loadPackageAsync(r, t));
}

loadTutorialMarkdown(repopath: string, tag?: string): Promise<pxt.github.CachedPackage> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious why we need a function like this defined in so many places? I see that the one defined in the github namespace is getting used along with db.loadTutorialMarkdown, but what do each of these allow for us to do?

Copy link
Contributor

Choose a reason for hiding this comment

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

Same question for the cacheReposAsync function.

Copy link
Member Author

Choose a reason for hiding this comment

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

it's defined on the githubdb interface so all of the classes that implement that interface need to have it as well! i just propagated it to all of the existing ones we have, i don't actually know what this one in the CLI is used for.

Copy link
Contributor

@srietkerk srietkerk left a comment

Choose a reason for hiding this comment

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

Just a question for my own understanding. Looks good!

@riknoll riknoll merged commit 712a05f into master Oct 24, 2024
6 checks passed
@riknoll riknoll deleted the dev/riknoll/tutorial-bundle branch October 24, 2024 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants