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

repo sync #16386

Merged
merged 2 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
don't need disk caching for site data (#26333)
* reinstate

* start server manually

* routing tests too

* skip more

* sleep more and fail if not 200

* use e2etest for content/ too

* automatically start server for jest

* does this work?

* feedbacked

* rename things

* getting it to work

* add dev dependency

* install the right version

* don't need to start that

* fix package lock

* update readme about it

* feedbacked

* don't need disk caching for site-data
  • Loading branch information
peterbe authored Mar 19, 2022
commit b685b6fda716ebd5ce3023c462523016c86bf0b6
5 changes: 0 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,6 @@ jobs:
- name: Run build script
run: npm run build

- name: Warm possible disk caching
env:
NODE_ENV: test
run: ./script/warm-before-tests.mjs

- name: Run tests
env:
DIFF_FILE: get_diff_files.txt
Expand Down
29 changes: 2 additions & 27 deletions lib/site-data.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,11 @@
import fs from 'fs'
import os from 'os'
import path from 'path'
import flat from 'flat'
import { get, set } from 'lodash-es'
import languages from './languages.js'
import dataDirectory from './data-directory.js'
import encodeBracketedParentheses from './encode-bracketed-parentheses.js'

const TEMP_DIRECTORY = process.env.RUNNER_TEMP || os.tmpdir()

function diskMemoize(prefix, fn) {
const useCache = process.env.NODE_ENV !== 'development'
return (dir) => {
const cacheFileName = `${prefix}.${dir.replace(/[^\w]+/g, '-').toLowerCase() || 'en'}.json`
if (useCache) {
try {
return JSON.parse(fs.readFileSync(cacheFileName, 'utf-8'))
} catch (err) {
if (!(err.code === 'ENOENT' || err instanceof SyntaxError)) throw err
}
}

const result = fn(dir)
if (useCache) {
fs.writeFileSync(cacheFileName, JSON.stringify(result), 'utf-8')
console.log(`Disk-cache miss on ${cacheFileName}`, new Date())
}
return result
}
}

const loadSiteDataFromDir = diskMemoize(path.join(TEMP_DIRECTORY, 'docs-site-data'), (dir) => {
const loadSiteDataFromDir = (dir) => {
return {
site: {
data: dataDirectory(path.join(dir, 'data'), {
Expand All @@ -39,7 +14,7 @@ const loadSiteDataFromDir = diskMemoize(path.join(TEMP_DIRECTORY, 'docs-site-dat
}),
},
}
})
}

export default function loadSiteData() {
// load English site data
Expand Down
22 changes: 0 additions & 22 deletions script/warm-before-tests.mjs

This file was deleted.