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

Improve usability of caches #468

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defaults:


concurrency:
group: ${{ github.workflow }} # do not allow any concurrency or the different builds will fight for the github rate limit and all take far longer
group: uses-github-api # do not allow any concurrency or the different builds will fight for the github rate limit and all take far longer

jobs:
unit-test:
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/check-external-links.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
name: Check external links

on:
push:
branches:
[ main ]
schedule: ## Do a run once times daily, to catch new regressions
schedule: ## Do a run once daily, to catch new regressions
- cron: '45 10 * * *'
workflow_dispatch:

Expand All @@ -13,7 +10,7 @@ defaults:
shell: bash

concurrency:
group: ${{ github.workflow }} # do not allow any concurrency or the different builds will risk creating multiple issues
group: uses-github-api # do not allow any concurrency or the different builds will risk creating multiple issues

jobs:
build:
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ nvm use 18
Information is more complete if a GitHub access token is provided. It should only be granted read access.
Set it as an environment variable called `GITHUB_TOKEN`. (In the CI, this will be provided by the platform.)

## Caching

The site pulls down a lot of content through the GitHub API.
A full build of the site will trigger the rate limiter several times. Each time the rate limiter is hit, the build needs to wait an hour for it to roll over.
Because of this, a fresh build could take two or three hours – be prepared! To build more quickly (but with incomplete information), use the `npm run develop:quickly` command.

The build caches GitHub content in a cache in the `.cache-github-api/` directory, so once a build has been done, subsequent builds should be quicker.
Most cache contents have a lifespan of a few days (with some jitter so everything doesn't expire at once).

In one terminal, run tests
```
npm install
Expand All @@ -41,6 +50,8 @@ In another terminal, run the site
npm run develop
```

(or `npm run develop:quickly` if you're in a hurry and don't need all the source control data)

You can then see changes live on http://localhost:8000.

# Local production-like development
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"scripts": {
"build": "cp ./node_modules/gatsby-page-utils/dist/apply-trailing-slash-option.js ./node_modules/gatsby-page-utils && gatsby build",
"develop": "gatsby develop",
"develop:quickly": "DONT_WAIT=true gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
"start": "cp ./node_modules/gatsby-page-utils/dist/apply-trailing-slash-option.js ./node_modules/gatsby-page-utils && gatsby develop",
"serve": "gatsby serve",
Expand Down
3 changes: 2 additions & 1 deletion plugins/github-enricher/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ const createContributingCompanies = async ({ actions, createNodeId, createConten
}, { sponsor: company, source: extensionCatalogContributingCompany }))

} else {
console.warn("Could not fetch sponsor opt in information from", url, ". Does the file exist?")
console.warn("Could not fetch sponsor opt in information from", org, repo, path, ". Does the file exist?")
}
}

Expand Down Expand Up @@ -589,6 +589,7 @@ exports.createSchemaCustomization = ({ actions }) => {
url: String
ownerImageUrl: String
extensionYamlUrl: String
extensionRootUrl: String
issues: String
lastUpdated: String
contributors: [ContributorInfo]
Expand Down
11 changes: 7 additions & 4 deletions plugins/github-enricher/github-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const RATE_LIMIT_PREQUERY = `rateLimit {
}`

let resetTime
const allowSlowBuild = !process.env.DONT_WAIT

// We can add more errors we know are non-recoverable here, which should help build times
const isRecoverableError = (ghBody, params) => {
Expand Down Expand Up @@ -46,13 +47,15 @@ async function tolerantFetch(url, params, isSuccessful, getContents) {
if (!isSuccessful(ghBody) && isRecoverableError(ghBody, params)) {
const responseString = JSON.stringify(ghBody)

if (responseString?.includes("RATE_LIMITED") && resetTime) {
if (allowSlowBuild && responseString?.includes("RATE_LIMITED") && resetTime) {
console.warn("Hit the rate limit. Waiting until", resetTime)
await waitUntil(resetTime)
}
retry(
`Unsuccessful GitHub fetch for ${url} - response is ${responseString}`
)
if (allowSlowBuild) {
retry(
`Unsuccessful GitHub fetch for ${url} - response is ${responseString}`
)
}
}
return ghBody
},
Expand Down
Loading