Skip to content

Commit d51e3f5

Browse files
committed
partial changes πŸ™…β€β™€οΈ
1 parent 651d2d6 commit d51e3f5

File tree

5 files changed

+3
-65
lines changed

5 files changed

+3
-65
lines changed

β€Žcoderd/agentapi/stats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (a *StatsAPI) UpdateStats(ctx context.Context, req *agentproto.UpdateStatsR
140140
}
141141

142142
func (a *StatsAPI) publishWorkspaceAgentStats(ctx context.Context, workspaceID uuid.UUID) {
143-
err := a.Pubsub.Publish(codersdk.WorkspaceNotifyChannel(workspaceID), codersdk.WorkspaceNotifyDescriptionAgentStatsOnly)
143+
err := a.Pubsub.Publish(codersdk.WorkspaceNotifyChannel(workspaceID), []byte{})
144144
if err != nil {
145145
a.Log.Warn(ctx, "failed to publish workspace agent stats",
146146
slog.F("workspace_id", workspaceID), slog.Error(err))

β€Žcoderd/agentapi/stats_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func TestUpdateStates(t *testing.T) {
175175
publishAgentStats := make(chan bool)
176176
ps.Subscribe(codersdk.WorkspaceNotifyChannel(workspace.ID), func(_ context.Context, description []byte) {
177177
go func() {
178-
publishAgentStats <- bytes.Equal(description, codersdk.WorkspaceNotifyDescriptionAgentStatsOnly)
178+
publishAgentStats <- bytes.Equal(description, []byte{})
179179
close(publishAgentStats)
180180
}()
181181
})

β€Žcoderd/workspaces.go

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package coderd
22

33
import (
4-
"bytes"
54
"context"
65
"database/sql"
76
"encoding/json"
@@ -1345,47 +1344,6 @@ func (api *API) watchWorkspace(rw http.ResponseWriter, r *http.Request) {
13451344
}()
13461345

13471346
sendUpdate := func(_ context.Context, description []byte) {
1348-
// The agent stats get updated frequently, so we treat these as a special case and only
1349-
// send a partial update. We primarily care about updating the `last_used_at` and
1350-
// `latest_build.deadline` properties.
1351-
if bytes.Equal(description, codersdk.WorkspaceNotifyDescriptionAgentStatsOnly) {
1352-
workspace, err := api.Database.GetWorkspaceByID(ctx, workspace.ID)
1353-
if err != nil {
1354-
_ = sendEvent(ctx, codersdk.ServerSentEvent{
1355-
Type: codersdk.ServerSentEventTypeError,
1356-
Data: codersdk.Response{
1357-
Message: "Internal error fetching workspace.",
1358-
Detail: err.Error(),
1359-
},
1360-
})
1361-
return
1362-
}
1363-
1364-
workspaceBuild, err := api.Database.GetLatestWorkspaceBuildByWorkspaceID(ctx, workspace.ID)
1365-
if err != nil {
1366-
_ = sendEvent(ctx, codersdk.ServerSentEvent{
1367-
Type: codersdk.ServerSentEventTypeError,
1368-
Data: codersdk.Response{
1369-
Message: "Internal error fetching workspace build.",
1370-
Detail: err.Error(),
1371-
},
1372-
})
1373-
return
1374-
}
1375-
1376-
_ = sendEvent(ctx, codersdk.ServerSentEvent{
1377-
Type: codersdk.ServerSentEventTypePartial,
1378-
Data: struct {
1379-
database.Workspace
1380-
LatestBuild database.WorkspaceBuild `json:"latest_build"`
1381-
}{
1382-
Workspace: workspace,
1383-
LatestBuild: workspaceBuild,
1384-
},
1385-
})
1386-
return
1387-
}
1388-
13891347
workspace, err := api.Database.GetWorkspaceByID(ctx, workspace.ID)
13901348
if err != nil {
13911349
_ = sendEvent(ctx, codersdk.ServerSentEvent{

β€Žcodersdk/workspaces.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,6 @@ func (c *Client) UnfavoriteWorkspace(ctx context.Context, workspaceID uuid.UUID)
497497
return nil
498498
}
499499

500-
var WorkspaceNotifyDescriptionAgentStatsOnly = []byte("agentStatsOnly")
501-
502500
// WorkspaceNotifyChannel is the PostgreSQL NOTIFY
503501
// channel to listen for updates on. The payload is empty,
504502
// because the size of a workspace payload can be very large.

β€Žsite/src/pages/WorkspacePage/WorkspacePage.tsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,6 @@ export const WorkspacePage: FC = () => {
7777
}
7878
},
7979
);
80-
const getWorkspaceData = useEffectEvent(() => {
81-
if (!workspace) {
82-
throw new Error("Applying an update for a workspace that is undefined.");
83-
}
84-
85-
return queryClient.getQueryData(
86-
workspaceQueryOptions.queryKey,
87-
) as Workspace;
88-
});
8980
const workspaceId = workspace?.id;
9081
useEffect(() => {
9182
if (!workspaceId) {
@@ -99,23 +90,14 @@ export const WorkspacePage: FC = () => {
9990
await updateWorkspaceData(newWorkspaceData);
10091
});
10192

102-
eventSource.addEventListener("partial", async (event) => {
103-
const newWorkspaceData = JSON.parse(event.data) as Partial<Workspace>;
104-
// Merge with a fresh object `{}` as the base, because `merge` uses an in-place algorithm,
105-
// and would otherwise mutate the `queryClient`'s internal state.
106-
await updateWorkspaceData(
107-
merge({}, getWorkspaceData(), newWorkspaceData),
108-
);
109-
});
110-
11193
eventSource.addEventListener("error", (event) => {
11294
console.error("Error on getting workspace changes.", event);
11395
});
11496

11597
return () => {
11698
eventSource.close();
11799
};
118-
}, [updateWorkspaceData, getWorkspaceData, workspaceId]);
100+
}, [updateWorkspaceData, workspaceId]);
119101

120102
// Page statuses
121103
const pageError =

0 commit comments

Comments
Β (0)