Skip to content

Commit

Permalink
don't need disk caching for site data (github#26333)
Browse files Browse the repository at this point in the history
* 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
1 parent ae8a928 commit b685b6f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 54 deletions.
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.

0 comments on commit b685b6f

Please sign in to comment.