fix: Downgrade log level for http cache cleanup (#28447)

This commit is contained in:
Sergei Zharinov 2024-04-16 12:05:39 -03:00 committed by GitHub
parent 41e6be8b94
commit 49005e0246
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 9 deletions

View file

@ -10,7 +10,7 @@ describe('util/cache/repository/http-cache', () => {
}); });
it('should not throw if cache is not a valid HttpCache', () => { it('should not throw if cache is not a valid HttpCache', () => {
expect(() => cleanupHttpCache('not a valid cache')).not.toThrow(); expect(() => cleanupHttpCache({})).not.toThrow();
}); });
it('should remove expired items from the cache', () => { it('should remove expired items from the cache', () => {

View file

@ -1,15 +1,15 @@
import is from '@sindresorhus/is';
import { DateTime } from 'luxon'; import { DateTime } from 'luxon';
import { GlobalConfig } from '../../../config/global'; import { GlobalConfig } from '../../../config/global';
import { logger } from '../../../logger'; import { logger } from '../../../logger';
import { HttpCacheSchema } from '../../http/cache/schema'; import { HttpCacheSchema } from '../../http/cache/schema';
import type { RepoCacheData } from './types';
export function cleanupHttpCache(cacheData: unknown): void { export function cleanupHttpCache(cacheData: RepoCacheData): void {
if (!is.plainObject(cacheData) || !is.plainObject(cacheData['httpCache'])) { const { httpCache } = cacheData;
logger.warn('cleanupHttpCache: invalid cache data'); if (!httpCache) {
logger.trace('cleanupHttpCache: no http cache to clean up');
return; return;
} }
const httpCache = cacheData['httpCache'];
const ttlDays = GlobalConfig.get('httpCacheTtlDays', 90); const ttlDays = GlobalConfig.get('httpCacheTtlDays', 90);
if (ttlDays === 0) { if (ttlDays === 0) {

View file

@ -71,9 +71,7 @@ export abstract class RepoCacheBase implements RepoCache {
} }
async save(): Promise<void> { async save(): Promise<void> {
if (this.data) { cleanupHttpCache(this.data);
cleanupHttpCache(this.data);
}
const jsonStr = safeStringify(this.data); const jsonStr = safeStringify(this.data);
const hashedJsonStr = hash(jsonStr); const hashedJsonStr = hash(jsonStr);
if (hashedJsonStr === this.oldHash) { if (hashedJsonStr === this.oldHash) {