Use common getTotalCacheSize for TRAP caching

This commit is contained in:
Michael B. Gale 2024-10-29 11:52:15 +00:00
parent 0cb71294e5
commit 21e6a62b15
No known key found for this signature in database
GPG key ID: FF5E2765BD00628F
9 changed files with 9 additions and 28 deletions

View file

@ -16,7 +16,7 @@ import {
} from "./analyze";
import { getApiDetails, getGitHubVersion } from "./api-client";
import { runAutobuild } from "./autobuild";
import { shouldStoreCache } from "./caching-utils";
import { getTotalCacheSize, shouldStoreCache } from "./caching-utils";
import { getCodeQL } from "./codeql";
import { Config, getConfig } from "./config-utils";
import { uploadDatabases } from "./database-upload";
@ -36,7 +36,6 @@ import {
} from "./status-report";
import {
cleanupTrapCaches,
getTotalCacheSize,
TrapCacheCleanupStatusReport,
uploadTrapCaches,
} from "./trap-caching";
@ -94,7 +93,7 @@ async function sendStatusReport(
...report,
trap_cache_upload_duration_ms: Math.round(trapCacheUploadTime || 0),
trap_cache_upload_size_bytes: Math.round(
await getTotalCacheSize(config.trapCaches, logger),
await getTotalCacheSize(Object.values(config.trapCaches), logger),
),
};
await statusReport.sendStatusReport(trapCacheUploadStatusReport);

View file

@ -17,6 +17,7 @@ import {
import { getGitHubVersion } from "./api-client";
import {
getDependencyCachingEnabled,
getTotalCacheSize,
shouldRestoreCache,
} from "./caching-utils";
import { CodeQL } from "./codeql";
@ -51,7 +52,6 @@ import {
import { ZstdAvailability } from "./tar";
import { ToolsDownloadStatusReport } from "./tools-download";
import { ToolsFeature } from "./tools-features";
import { getTotalCacheSize } from "./trap-caching";
import {
checkDiskUsage,
checkForTimeout,
@ -230,7 +230,7 @@ async function sendCompletedStatusReport(
packs: JSON.stringify(packs),
trap_cache_languages: Object.keys(config.trapCaches).join(","),
trap_cache_download_size_bytes: Math.round(
await getTotalCacheSize(config.trapCaches, logger),
await getTotalCacheSize(Object.values(config.trapCaches), logger),
),
trap_cache_download_duration_ms: Math.round(config.trapCacheDownloadTime),
query_filters: JSON.stringify(

View file

@ -312,18 +312,6 @@ export async function getLanguagesSupportingCaching(
return result;
}
export async function getTotalCacheSize(
trapCaches: Partial<Record<Language, string>>,
logger: Logger,
): Promise<number> {
const sizes = await Promise.all(
Object.values(trapCaches).map((cacheDir) =>
tryGetFolderBytes(cacheDir, logger),
),
);
return sizes.map((a) => a || 0).reduce((a, b) => a + b, 0);
}
async function cacheKey(
codeql: CodeQL,
language: Language,