Yicong-Huang commented on code in PR #8552:
URL: https://github.com/apache/texera/pull/8552#discussion_r4053539191


##########
frontend/src/app/workspace/service/heatmap/heatmap-stats-restore.service.ts:
##########
@@ -0,0 +1,105 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { Injectable } from "@angular/core";
+import { EMPTY, Observable, of } from "rxjs";
+import { catchError, map, switchMap } from "rxjs/operators";
+import { WorkflowExecutionsService } from 
"../../../dashboard/service/user/workflow-executions/workflow-executions.service";
+import { WorkflowExecutionsEntry } from 
"../../../dashboard/type/workflow-executions-entry";
+import { WorkflowActionService } from 
"../workflow-graph/model/workflow-action.service";
+import { WorkflowStatusService } from 
"../workflow-status/workflow-status.service";
+import { ExecuteWorkflowService } from 
"../execute-workflow/execute-workflow.service";
+import { isNotInExecution } from "../../types/execute-workflow.interface";
+import { loadPersistedHeatmapView } from "./heatmap-overlay-persistence";
+import { toOperatorRuntimeStatusMap } from "./runtime-statistics-mapper";
+
+/** Persisted execution status code for a completed run 
(EXECUTION_STATUS_CODE). */
+const EXECUTION_COMPLETED_CODE = 3;
+
+/**
+ * Restores the last execution's per-operator statistics after a page refresh,
+ * so the performance heat-map can render a finished run without re-executing.
+ *
+ * All gating lives here rather than in the caller: the persisted-overlay check
+ * is a synchronous localStorage read, so a user who never enabled the overlay
+ * incurs no fetch at all.
+ */
+@Injectable({
+  providedIn: "root",
+})
+export class HeatmapStatsRestoreService {
+  constructor(
+    private workflowExecutionsService: WorkflowExecutionsService,
+    private workflowActionService: WorkflowActionService,
+    private workflowStatusService: WorkflowStatusService,
+    private executeWorkflowService: ExecuteWorkflowService
+  ) {}
+
+  /**
+   * Fetches the latest run's statistics and feeds them into
+   * WorkflowStatusService. Cold: nothing happens until subscribed. Skips
+   * silently (including on HTTP errors — restoring is best-effort) when:
+   * - the overlay is not persisted on,
+   * - the workflow has never been saved (no wid),
+   * - an execution is in progress (the live stream wins),
+   * - the workflow has no executions or the run left no statistics.
+   */
+  public restoreLatestRunStatistics(): Observable<void> {
+    if (loadPersistedHeatmapView() === null) {
+      return EMPTY;
+    }
+    const wid = this.workflowActionService.getWorkflowMetadata()?.wid;
+    if (wid === undefined) {
+      return EMPTY;
+    }
+    if 
(!isNotInExecution(this.executeWorkflowService.getExecutionState().state)) {

Review Comment:
   The reconnect half is closed. `defer()` at `:62` and the re-check at `:90` 
both check out, and the three new specs pin them.
   
   A second trigger reaches the same gate and this does not catch it. Clicking 
Run calls `resetExecutionState()` (`execute-workflow.service.ts:217`), which 
sets `this.currentState = { state: ExecutionState.Uninitialized }` 
(`:382-385`), and `isNotInExecution` is true for `Uninitialized`, so 
`isExecuting()` here still reads false until the backend's `WorkflowStateEvent` 
comes back a round trip later. Reload with the overlay on, press Run before the 
two fetches return, and the `tap` writes the previous run's statistics and 
`Completed` states over the canvas `resetStatus()` (`:218`) just cleared. It 
stays wrong until the first live stats event, which 
`ExecutionStatsService.scala:105` only emits once operator metrics change, so 
after compile and worker startup.
   
   `takeUntil(this.workflowStatusService.getStatisticsUpdateStream())` 
immediately above the `tap` covers both triggers. `statisticsSubject` is a 
plain `Subject` (`workflow-status.service.ts:37`), so it never fires on 
subscribe, only when another producer writes first, and the restore's own write 
sits downstream of it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to