mirror of
https://github.com/thepeacockproject/Peacock
synced 2024-11-16 11:03:30 +01:00
refactor: Remove brotli encoding of contracts
It takes entire seconds to compress, and the memory overhead is huge when decompressing.
This commit is contained in:
parent
90c66b7858
commit
5f8ce8ff5f
@ -65,8 +65,6 @@ import { ChallengeService } from "./candle/challengeService"
|
||||
import { getFlag } from "./flags"
|
||||
import { unpack } from "msgpackr"
|
||||
import { ChallengePackage, SavedChallengeGroup } from "./types/challenges"
|
||||
import { promisify } from "util"
|
||||
import { brotliDecompress } from "zlib"
|
||||
import assert from "assert"
|
||||
import { Response } from "express"
|
||||
import { ChallengeFilterType } from "./candle/challengeHelpers"
|
||||
@ -1115,17 +1113,15 @@ export class Controller {
|
||||
}
|
||||
|
||||
private async _loadInternalContracts(): Promise<void> {
|
||||
const decompress = promisify(brotliDecompress)
|
||||
|
||||
const buf = await readFile(
|
||||
join(
|
||||
PEACOCK_DEV ? process.cwd() : __dirname,
|
||||
"resources",
|
||||
"contracts.br",
|
||||
"contracts.prp",
|
||||
),
|
||||
)
|
||||
|
||||
const decompressed = JSON.parse((await decompress(buf)).toString()) as {
|
||||
const decompressed = unpack(buf) as {
|
||||
b: MissionManifest[]
|
||||
el: MissionManifest[]
|
||||
}
|
||||
|
@ -586,6 +586,6 @@ export async function startServer(options: {
|
||||
return
|
||||
} catch (e) {
|
||||
log(LogLevel.ERROR, "Critical error during bootstrap!")
|
||||
log(LogLevel.ERROR, e)
|
||||
log(LogLevel.ERROR, (e as Error)?.stack ?? e)
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,6 @@ import millis from "ms"
|
||||
import { mkdir, readdir, readFile, unlink, writeFile } from "fs/promises"
|
||||
import { createHash } from "crypto"
|
||||
import { Packr } from "msgpackr"
|
||||
import { brotliCompress } from "zlib"
|
||||
import { promisify } from "util"
|
||||
import glob from "fast-glob"
|
||||
import prettier from "prettier"
|
||||
|
||||
@ -197,9 +195,8 @@ export async function packResources() {
|
||||
}
|
||||
}
|
||||
|
||||
const d = JSON.stringify({ b, el })
|
||||
const compressed = await promisify(brotliCompress)(d)
|
||||
await writeFile("resources/contracts.br", compressed)
|
||||
const compressed = packer.pack({ b, el })
|
||||
await writeFile("resources/contracts.prp", compressed)
|
||||
|
||||
console.log(
|
||||
`Gathered built-in contracts and challenges in ${millis(
|
||||
|
Loading…
Reference in New Issue
Block a user