mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 14:36:25 +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),
|
getKey(namespace, key),
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
compress: true,
|
compress: true,
|
||||||
value: await compressToBase64(value),
|
value: await compressToBase64(JSON.stringify(value)),
|
||||||
expiry: DateTime.local().plus({ minutes: ttlMinutes }),
|
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),
|
getKey(namespace, key),
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
compress: true,
|
compress: true,
|
||||||
value: await compressToBase64(value),
|
value: await compressToBase64(JSON.stringify(value)),
|
||||||
expiry: DateTime.local().plus({ minutes: ttlMinutes }),
|
expiry: DateTime.local().plus({ minutes: ttlMinutes }),
|
||||||
}),
|
}),
|
||||||
{ EX: redisTTL },
|
{ EX: redisTTL },
|
||||||
|
|
|
@ -10,14 +10,4 @@ describe('util/compress', () => {
|
||||||
const decompressed = await decompressFromBase64(compressed);
|
const decompressed = await decompressFromBase64(compressed);
|
||||||
expect(decompressed).toBe(input);
|
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 { promisify } from 'node:util';
|
||||||
import zlib, { constants } from 'node:zlib';
|
import zlib, { constants } from 'node:zlib';
|
||||||
import is from '@sindresorhus/is';
|
|
||||||
|
|
||||||
const brotliCompress = promisify(zlib.brotliCompress);
|
const brotliCompress = promisify(zlib.brotliCompress);
|
||||||
const brotliDecompress = promisify(zlib.brotliDecompress);
|
const brotliDecompress = promisify(zlib.brotliDecompress);
|
||||||
|
@ -8,9 +7,8 @@ const brotliDecompress = promisify(zlib.brotliDecompress);
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
export async function compressToBase64(input: unknown): Promise<string> {
|
export async function compressToBase64(input: string): Promise<string> {
|
||||||
const jsonStr = is.string(input) ? input : JSON.stringify(input);
|
const buf = await brotliCompress(input, {
|
||||||
const buf = await brotliCompress(jsonStr, {
|
|
||||||
params: {
|
params: {
|
||||||
[constants.BROTLI_PARAM_MODE]: constants.BROTLI_MODE_TEXT,
|
[constants.BROTLI_PARAM_MODE]: constants.BROTLI_MODE_TEXT,
|
||||||
[constants.BROTLI_PARAM_QUALITY]: 8,
|
[constants.BROTLI_PARAM_QUALITY]: 8,
|
||||||
|
|
Loading…
Reference in a new issue