mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 06:26:26 +00:00
fix(cache): Fix compression and decompression format mismatch (#27021)
This commit is contained in:
parent
5d7770c5b5
commit
68d5faa96e
4 changed files with 4 additions and 16 deletions
2
lib/util/cache/package/file.ts
vendored
2
lib/util/cache/package/file.ts
vendored
|
@ -58,7 +58,7 @@ export async function set(
|
|||
getKey(namespace, key),
|
||||
JSON.stringify({
|
||||
compress: true,
|
||||
value: await compressToBase64(value),
|
||||
value: await compressToBase64(JSON.stringify(value)),
|
||||
expiry: DateTime.local().plus({ minutes: ttlMinutes }),
|
||||
}),
|
||||
);
|
||||
|
|
2
lib/util/cache/package/redis.ts
vendored
2
lib/util/cache/package/redis.ts
vendored
|
@ -71,7 +71,7 @@ export async function set(
|
|||
getKey(namespace, key),
|
||||
JSON.stringify({
|
||||
compress: true,
|
||||
value: await compressToBase64(value),
|
||||
value: await compressToBase64(JSON.stringify(value)),
|
||||
expiry: DateTime.local().plus({ minutes: ttlMinutes }),
|
||||
}),
|
||||
{ EX: redisTTL },
|
||||
|
|
|
@ -10,14 +10,4 @@ describe('util/compress', () => {
|
|||
const decompressed = await decompressFromBase64(compressed);
|
||||
expect(decompressed).toBe(input);
|
||||
});
|
||||
|
||||
it('compresses objects', async () => {
|
||||
const input = { foo: 'bar' };
|
||||
|
||||
const compressed = await compressToBase64(input);
|
||||
expect(compressed).toBe('CwaAeyJmb28iOiJiYXIifQM=');
|
||||
|
||||
const decompressed = await decompressFromBase64(compressed);
|
||||
expect(JSON.parse(decompressed)).toEqual(input);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { promisify } from 'node:util';
|
||||
import zlib, { constants } from 'node:zlib';
|
||||
import is from '@sindresorhus/is';
|
||||
|
||||
const brotliCompress = promisify(zlib.brotliCompress);
|
||||
const brotliDecompress = promisify(zlib.brotliDecompress);
|
||||
|
@ -8,9 +7,8 @@ const brotliDecompress = promisify(zlib.brotliDecompress);
|
|||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export async function compressToBase64(input: unknown): Promise<string> {
|
||||
const jsonStr = is.string(input) ? input : JSON.stringify(input);
|
||||
const buf = await brotliCompress(jsonStr, {
|
||||
export async function compressToBase64(input: string): Promise<string> {
|
||||
const buf = await brotliCompress(input, {
|
||||
params: {
|
||||
[constants.BROTLI_PARAM_MODE]: constants.BROTLI_MODE_TEXT,
|
||||
[constants.BROTLI_PARAM_QUALITY]: 8,
|
||||
|
|
Loading…
Reference in a new issue