mirror of
https://github.com/thepeacockproject/Peacock
synced 2025-03-21 00:04:22 +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 { getFlag } from "./flags"
|
||||||
import { unpack } from "msgpackr"
|
import { unpack } from "msgpackr"
|
||||||
import { ChallengePackage, SavedChallengeGroup } from "./types/challenges"
|
import { ChallengePackage, SavedChallengeGroup } from "./types/challenges"
|
||||||
import { promisify } from "util"
|
|
||||||
import { brotliDecompress } from "zlib"
|
|
||||||
import assert from "assert"
|
import assert from "assert"
|
||||||
import { Response } from "express"
|
import { Response } from "express"
|
||||||
import { ChallengeFilterType } from "./candle/challengeHelpers"
|
import { ChallengeFilterType } from "./candle/challengeHelpers"
|
||||||
@ -1115,17 +1113,15 @@ export class Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _loadInternalContracts(): Promise<void> {
|
private async _loadInternalContracts(): Promise<void> {
|
||||||
const decompress = promisify(brotliDecompress)
|
|
||||||
|
|
||||||
const buf = await readFile(
|
const buf = await readFile(
|
||||||
join(
|
join(
|
||||||
PEACOCK_DEV ? process.cwd() : __dirname,
|
PEACOCK_DEV ? process.cwd() : __dirname,
|
||||||
"resources",
|
"resources",
|
||||||
"contracts.br",
|
"contracts.prp",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
const decompressed = JSON.parse((await decompress(buf)).toString()) as {
|
const decompressed = unpack(buf) as {
|
||||||
b: MissionManifest[]
|
b: MissionManifest[]
|
||||||
el: MissionManifest[]
|
el: MissionManifest[]
|
||||||
}
|
}
|
||||||
|
@ -586,6 +586,6 @@ export async function startServer(options: {
|
|||||||
return
|
return
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(LogLevel.ERROR, "Critical error during bootstrap!")
|
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 { mkdir, readdir, readFile, unlink, writeFile } from "fs/promises"
|
||||||
import { createHash } from "crypto"
|
import { createHash } from "crypto"
|
||||||
import { Packr } from "msgpackr"
|
import { Packr } from "msgpackr"
|
||||||
import { brotliCompress } from "zlib"
|
|
||||||
import { promisify } from "util"
|
|
||||||
import glob from "fast-glob"
|
import glob from "fast-glob"
|
||||||
import prettier from "prettier"
|
import prettier from "prettier"
|
||||||
|
|
||||||
@ -197,9 +195,8 @@ export async function packResources() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const d = JSON.stringify({ b, el })
|
const compressed = packer.pack({ b, el })
|
||||||
const compressed = await promisify(brotliCompress)(d)
|
await writeFile("resources/contracts.prp", compressed)
|
||||||
await writeFile("resources/contracts.br", compressed)
|
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`Gathered built-in contracts and challenges in ${millis(
|
`Gathered built-in contracts and challenges in ${millis(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user