Skip to content

Commit

Permalink
Use common getTotalCacheSize for TRAP caching
Browse files Browse the repository at this point in the history
  • Loading branch information
mbg committed Oct 29, 2024
1 parent 0cb7129 commit 21e6a62
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/analyze-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/analyze-action.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions lib/init-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/init-action.js.map

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions lib/trap-caching.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/trap-caching.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/analyze-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -36,7 +36,6 @@ import {
} from "./status-report";
import {
cleanupTrapCaches,
getTotalCacheSize,
TrapCacheCleanupStatusReport,
uploadTrapCaches,
} from "./trap-caching";
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/init-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { getGitHubVersion } from "./api-client";
import {
getDependencyCachingEnabled,
getTotalCacheSize,
shouldRestoreCache,
} from "./caching-utils";
import { CodeQL } from "./codeql";
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 0 additions & 12 deletions src/trap-caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 21e6a62

Please sign in to comment.