Skip to content

Commit 806060f

Browse files
authored
Merge pull request #418 from rajbos/copilot/fix-dashboard-loading-issue
Fix Team Dashboard slow initial render by caching last fetch result
2 parents ac7ff68 + f090465 commit 806060f

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

src/extension.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class CopilotTokenTracker implements vscode.Disposable {
171171
private lastDetailedStats: DetailedStats | undefined;
172172
private lastDailyStats: DailyTokenStats[] | undefined;
173173
private lastUsageAnalysisStats: UsageAnalysisStats | undefined;
174+
private lastDashboardData: any | undefined;
174175
private tokenEstimators: { [key: string]: number } = tokenEstimatorsData.estimators;
175176
private co2Per1kTokens = 0.2; // gCO2e per 1000 tokens, a rough estimate
176177
private co2AbsorptionPerTreePerYear = 21000; // grams of CO2 per tree per year
@@ -357,6 +358,7 @@ class CopilotTokenTracker implements vscode.Disposable {
357358
this.lastDetailedStats = undefined;
358359
this.lastDailyStats = undefined;
359360
this.lastUsageAnalysisStats = undefined;
361+
this.lastDashboardData = undefined;
360362

361363
this.log(`Cache cleared successfully. Removed ${cacheSize} entries.`);
362364
vscode.window.showInformationMessage('Cache cleared successfully. Reloading statistics...');
@@ -4828,20 +4830,33 @@ ${hashtag}`;
48284830
this.dashboardPanel = undefined;
48294831
});
48304832

4831-
// Load data asynchronously and send to webview
4833+
// If we have cached data, show it immediately so the panel renders fast
4834+
if (this.lastDashboardData) {
4835+
this.log("📊 Sending cached dashboard data immediately");
4836+
this.dashboardPanel.webview.postMessage({
4837+
command: "dashboardData",
4838+
data: this.lastDashboardData,
4839+
});
4840+
}
4841+
4842+
// Load (or refresh) data asynchronously and send to webview
48324843
try {
48334844
const dashboardData = await this.getDashboardData();
4845+
this.lastDashboardData = dashboardData;
48344846
this.dashboardPanel?.webview.postMessage({
48354847
command: "dashboardData",
48364848
data: dashboardData,
48374849
});
48384850
} catch (error) {
48394851
this.error("Failed to load dashboard data:", error);
4840-
this.dashboardPanel?.webview.postMessage({
4841-
command: "dashboardError",
4842-
message:
4843-
"Failed to load dashboard data. Please check backend configuration and try again.",
4844-
});
4852+
// Only show error state when there's no cached data to fall back on
4853+
if (!this.lastDashboardData) {
4854+
this.dashboardPanel?.webview.postMessage({
4855+
command: "dashboardError",
4856+
message:
4857+
"Failed to load dashboard data. Please check backend configuration and try again.",
4858+
});
4859+
}
48454860
}
48464861
}
48474862

@@ -4854,6 +4869,7 @@ ${hashtag}`;
48544869
this.dashboardPanel.webview.postMessage({ command: "dashboardLoading" });
48554870
try {
48564871
const dashboardData = await this.getDashboardData();
4872+
this.lastDashboardData = dashboardData;
48574873
this.dashboardPanel?.webview.postMessage({
48584874
command: "dashboardData",
48594875
data: dashboardData,

0 commit comments

Comments
 (0)