Skip to content

Commit 889e7b5

Browse files
committed
Remove non-existent workspace data from global storage and extend cache pruning to 3 months
1 parent c770fb7 commit 889e7b5

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎apps/editor/src/commands/apply-context-command/helpers/saving/global-storage-utils.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,15 @@ export const save_contexts_for_workspace = (
5151
const all_data = load_all_global_contexts_data(context)
5252
all_data[workspace_root] = contexts
5353

54+
const filtered_data: GlobalContextsData = {}
55+
for (const root in all_data) {
56+
if (fs.existsSync(root)) {
57+
filtered_data[root] = all_data[root]
58+
}
59+
}
60+
5461
try {
55-
fs.writeFileSync(file_path, JSON.stringify(all_data, null, 2), 'utf8')
62+
fs.writeFileSync(file_path, JSON.stringify(filtered_data, null, 2), 'utf8')
5663
} catch (error) {
5764
console.error('Error saving global contexts:', error)
5865
throw new Error('Failed to save contexts to global storage.')

‎apps/editor/src/context/providers/workspace/modules/token-calculator.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,13 @@ export class TokenCalculator implements vscode.Disposable {
103103
}
104104
}
105105

106-
// Prune workspaces updated one week ago or later
107-
const one_week_ago = Date.now() - 7 * 24 * 60 * 60 * 1000
106+
// Prune workspaces that no longer exist or were updated more than 3 months ago
107+
const three_months_ago = Date.now() - 90 * 24 * 60 * 60 * 1000
108108
for (const root in current_global_cache) {
109-
if (current_global_cache[root].modified_at < one_week_ago) {
109+
if (
110+
!fs.existsSync(root) ||
111+
current_global_cache[root].modified_at < three_months_ago
112+
) {
110113
delete current_global_cache[root]
111114
}
112115
}

0 commit comments

Comments
 (0)