This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
446 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TILES_URL=staging-tiles.radverkehrsatlas.de |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
src | ||
*.log | ||
.env.local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# About | ||
|
||
… | ||
|
||
## Run locally | ||
|
||
1. Edit [`.env`](.env) | ||
2. Run… | ||
|
||
``` | ||
cd ./cache-warming | ||
time node ./warmCache.js | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"viewport": { | ||
"width": 800, | ||
"height": 600 | ||
}, | ||
"map": { | ||
"lat": 52.3968, | ||
"lng": 13.0342, | ||
"zoomFrom": 8, | ||
"zoomTo": 11 | ||
}, | ||
"urls": [ | ||
"/roads/{z}/{x}/{y}", | ||
"/roadsPathClasses/{z}/{x}/{y}", | ||
"/bikelanes_verified/{z}/{x}/{y}", | ||
"/poiClassification/{z}/{x}/{y}", | ||
"/boundaries,boundaryLabels/{z}/{x}/{y}", | ||
"/boundaryStats/{z}/{x}/{y}", | ||
"/publicTransport/{z}/{x}/{y}", | ||
"/places/{z}/{x}/{y}", | ||
"/barrierAreas,barrierLines/{z}/{x}/{y}", | ||
"/landuse/{z}/{x}/{y}", | ||
"/bicycleParking_points,bicycleParking_areas/{z}/{x}/{y}", | ||
"/trafficSigns/{z}/{x}/{y}" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env bun | ||
|
||
import { sources } from '../../atlas-app/src/app/regionen/[regionSlug]/_mapData/mapDataSources/sources.const' | ||
import { staticRegion } from '../../atlas-app/src/app/regionen/(index)/_data/regions.const' | ||
import { getTilesUrl } from '../../atlas-app/src/app/_components/utils/getTilesUrl' | ||
|
||
|
||
const regionSlug = 'bb' | ||
const cacheWarmingConfigPath = 'config.json' | ||
|
||
const viewport = { | ||
width: 800, | ||
height: 600, | ||
} | ||
|
||
const zoomOutLevels = 0 | ||
const zoomInLevels = 0 | ||
|
||
const region = staticRegion.find((region) => region.slug === regionSlug) | ||
|
||
const tilesUrl = getTilesUrl() | ||
const urls = sources | ||
.map((source) => { | ||
return source.tiles | ||
}) | ||
.filter((url) => url.startsWith(tilesUrl) && url.endsWith('{z}/{x}/{y}')) | ||
.map((url) => { | ||
return url.replace(tilesUrl, '') | ||
}) | ||
|
||
const data = { | ||
viewport, | ||
map: { | ||
lat: region!.map.lat, | ||
lng: region!.map.lng, | ||
zoomFrom: region!.map.zoom - zoomOutLevels, | ||
zoomTo: region!.map.zoom + zoomInLevels | ||
}, | ||
urls, | ||
} | ||
|
||
const config = JSON.stringify(data, null, 2) | ||
Bun.write(cacheWarmingConfigPath, config) | ||
|
||
console.log(`${cacheWarmingConfigPath} saved.`) | ||
console.log(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/usr/bin/env bun | ||
|
||
import { parseArgs } from 'node:util' | ||
import fs from 'node:fs' | ||
import chalk from 'chalk' | ||
import { parseSize, parseTime, displayHelp } from './util' | ||
|
||
function error(message) { | ||
console.error(message) | ||
process.exit() | ||
} | ||
|
||
let parsed: any | ||
try { | ||
parsed = parseArgs({ | ||
options: { | ||
help: { type: 'boolean', default: false }, | ||
'size': { type: 'string', short: 's' }, | ||
'time': { type: 'string', short: 't' }, | ||
grep: { type: 'string', short: 'g' }, | ||
'skip-errors': { type: 'boolean', short: 'e', default: false }, | ||
hit: { type: 'boolean', short: 'h', default: false }, | ||
miss: { type: 'boolean', short: 'm', default: false }, | ||
}, | ||
strict: true, | ||
allowPositionals: true, | ||
}) | ||
} catch (e) { | ||
error(e.message) | ||
} | ||
|
||
const { values, positionals } = parsed | ||
|
||
const args = { | ||
help: values.help, | ||
skipErrors: values['skip-errors'], | ||
minSize: 'size' in values ? parseSize(values.size) : null, | ||
minTime: 'time' in values ? parseTime(values.time) : null, | ||
grep: values.grep || null, | ||
hit: values.hit, | ||
miss: values.miss, | ||
} | ||
|
||
if (values.help) { | ||
displayHelp() | ||
process.exit(0) | ||
} | ||
|
||
if (positionals.length === 0) error('Logfile argument is missing.') | ||
if (positionals.length > 1) error('Too many arguments.') | ||
const filename = positionals[0] | ||
if (!fs.existsSync(filename)) error(`File "${filename}" not found.`) | ||
if (args.hit && args.miss) error('Supply only one of "hit" or "miss"') | ||
|
||
const logData = (await Bun.file(filename).text()).split('\n') | ||
let i = 0 | ||
while (i < logData.length) { | ||
const line = logData[i]! | ||
if (!'🡇✓⚠'.split('').includes(line[0]!)) { | ||
console.log(line) | ||
i++ | ||
continue | ||
} | ||
let request = line | ||
if (args.grep) { | ||
const f0 = request.search(args.grep) | ||
if (f0 === -1) { | ||
i += 2 | ||
continue | ||
} else { | ||
const f1 = f0 + args.grep.length | ||
request = request.slice(0, f0) + chalk.red(request.slice(f0, f1)) + request.slice(f1) | ||
} | ||
} | ||
const response = logData[i + 1]! | ||
if (!response) break | ||
|
||
let [cacheStatus, timeFormatted, sizeFormatted] = response.slice(2).split(' - ') | ||
if (response.startsWith('⚠')) { | ||
if (!args.skipErrors) { | ||
console.log(request) | ||
console.log(response) | ||
} | ||
} else if (args.hit && cacheStatus !== 'HIT') { | ||
// don't log | ||
} else if (args.miss && cacheStatus !== 'MISS') { | ||
// don't log | ||
} else if (args.minSize === null && args.minTime === null) { | ||
// don't log if neither minSize nor minTime is given | ||
} else { | ||
let [cacheStatus, timeFormatted, sizeFormatted] = response.slice(2).split(' - ') | ||
const logSize = args.minSize === null ? false : parseSize(sizeFormatted) >= args.minSize | ||
const logTime = args.minTime === null ? false : parseTime(timeFormatted) >= args.minTime | ||
if (logSize || logTime) { | ||
console.log(request) | ||
console.log(response) | ||
} | ||
} | ||
i += 2 | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "cachewarming", | ||
"version": "1.0.0", | ||
"main": "warmCache.js", | ||
"type": "module", | ||
"dependencies": { | ||
"chalk": "^5.3.0", | ||
"dotenv": "^16.4.5" | ||
} | ||
} |
Oops, something went wrong.