|
1 | 1 | import path from "node:path"; |
2 | 2 | import fs from "node:fs/promises"; |
3 | | -import {DatabaseSync} from "node:sqlite"; |
| 3 | +import BuildCacheStorage from "../build/cache/BuildCacheStorage.js"; |
4 | 4 |
|
5 | 5 | /** |
6 | 6 | * Get the size of a directory tree recursively. |
@@ -79,34 +79,17 @@ async function cleanBuildCache(buildCacheDir) { |
79 | 79 | return removed; |
80 | 80 | } |
81 | 81 |
|
82 | | - const tables = ["content", "index_cache", "stage_metadata", "task_metadata", "result_metadata"]; |
83 | 82 |
|
84 | 83 | for (const versionDir of versionDirs) { |
85 | 84 | if (!versionDir.isDirectory()) { |
86 | 85 | continue; |
87 | 86 | } |
88 | 87 |
|
89 | | - const dbPath = path.join(buildCacheDir, versionDir.name, "cache.db"); |
90 | | - try { |
91 | | - await fs.access(dbPath); |
92 | | - } catch { |
93 | | - continue; |
94 | | - } |
95 | | - |
96 | | - const statBefore = await fs.stat(dbPath); |
97 | | - const sizeBefore = statBefore.size; |
98 | | - |
99 | | - const db = new DatabaseSync(dbPath); |
100 | | - db.exec("BEGIN"); |
101 | | - for (const table of tables) { |
102 | | - db.exec(`DELETE FROM ${table}`); |
103 | | - } |
104 | | - db.exec("COMMIT"); |
105 | | - db.exec("VACUUM"); |
106 | | - db.close(); |
| 88 | + const dbDir = path.join(buildCacheDir, versionDir.name); |
107 | 89 |
|
108 | | - const statAfter = await fs.stat(dbPath); |
109 | | - const freedSize = sizeBefore - statAfter.size; |
| 90 | + const storage = new BuildCacheStorage(dbDir); |
| 91 | + const freedSize = storage.clearAllRecords(); |
| 92 | + storage.close(); |
110 | 93 |
|
111 | 94 | removed.push({ |
112 | 95 | path: `buildCache/${versionDir.name}`, |
|
0 commit comments