Skip to content

Commit

Permalink
fix(ui): do not rerender sidebar when non changes + update children i…
Browse files Browse the repository at this point in the history
…nstead of destroy/recreate (#5061)
  • Loading branch information
sguiheux authored Mar 23, 2020
1 parent 53fb4a2 commit 454d726
Show file tree
Hide file tree
Showing 29 changed files with 827 additions and 463 deletions.
20 changes: 14 additions & 6 deletions engine/api/workflow_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ func WorkflowSendEvent(ctx context.Context, db gorp.SqlExecutor, store cache.Sto
}
for _, wnr := range report.Nodes() {
wr, errWR := workflow.LoadRunByID(db, wnr.WorkflowRunID, workflow.LoadRunOptions{
WithLightTests: true,
DisableDetailledNodeRun: true,
})
if errWR != nil {
log.Warning(ctx, "WorkflowSendEvent> Cannot load workflow run %d: %s", wnr.WorkflowRunID, errWR)
log.Warning(ctx, "workflowSendEvent> Cannot load workflow run %d: %s", wnr.WorkflowRunID, errWR)
continue
}

Expand All @@ -36,11 +36,19 @@ func WorkflowSendEvent(ctx context.Context, db gorp.SqlExecutor, store cache.Sto
var errN error
previousNodeRun, errN = workflow.PreviousNodeRun(db, wnr, wnr.WorkflowNodeName, wr.WorkflowID)
if errN != nil {
log.Warning(ctx, "WorkflowSendEvent> Cannot load previous node run: %s", errN)
log.Warning(ctx, "workflowSendEvent> Cannot load previous node run: %v", errN)
}
}

event.PublishWorkflowNodeRun(ctx, db, store, wnr, wr.Workflow, &previousNodeRun)
nr, err := workflow.LoadNodeRunByID(db, wnr.ID, workflow.LoadRunOptions{
DisableDetailledNodeRun: true,
})
if err != nil {
log.Warning(ctx, "workflowSendEvent > Cannot load workflow node run: %v", err)
continue
}

event.PublishWorkflowNodeRun(ctx, db, store, *nr, wr.Workflow, &previousNodeRun)
e := &workflow.VCSEventMessenger{}
if err := e.SendVCSEvent(ctx, db, store, proj, *wr, wnr); err != nil {
log.Warning(ctx, "WorkflowSendEvent> Cannot send vcs notification")
Expand All @@ -50,14 +58,14 @@ func WorkflowSendEvent(ctx context.Context, db gorp.SqlExecutor, store cache.Sto
for _, jobrun := range report.Jobs() {
noderun, err := workflow.LoadNodeRunByID(db, jobrun.WorkflowNodeRunID, workflow.LoadRunOptions{})
if err != nil {
log.Warning(ctx, "WorkflowSendEvent> Cannot load workflow node run %d: %s", jobrun.WorkflowNodeRunID, err)
log.Warning(ctx, "workflowSendEvent> Cannot load workflow node run %d: %s", jobrun.WorkflowNodeRunID, err)
continue
}
wr, errWR := workflow.LoadRunByID(db, noderun.WorkflowRunID, workflow.LoadRunOptions{
WithLightTests: true,
})
if errWR != nil {
log.Warning(ctx, "WorkflowSendEvent> Cannot load workflow run %d: %s", noderun.WorkflowRunID, errWR)
log.Warning(ctx, "workflowSendEvent> Cannot load workflow run %d: %s", noderun.WorkflowRunID, errWR)
continue
}
event.PublishWorkflowNodeJobRun(ctx, db, proj.Key, *wr, jobrun)
Expand Down
8 changes: 3 additions & 5 deletions engine/api/workflow_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,12 @@ func postJobResult(ctx context.Context, dbFunc func(context.Context) *gorp.DbMap

for i := range report.WorkflowRuns() {
run := &report.WorkflowRuns()[i]
report, err := updateParentWorkflowRun(ctx, newDBFunc, store, run)
reportParent, err := updateParentWorkflowRun(ctx, newDBFunc, store, run)
if err != nil {
return nil, sdk.WithStack(err)
}

go WorkflowSendEvent(context.Background(), tx, store, *proj, report)
go WorkflowSendEvent(context.Background(), tx, store, *proj, reportParent)

if sdk.StatusIsTerminated(run.Status) {
//Start a goroutine to update commit statuses in repositories manager
Expand Down Expand Up @@ -675,9 +675,7 @@ func (api *API) postWorkflowJobStepStatusHandler() service.Handler {
}

if nodeRun.ID == 0 {
nodeRunP, err := workflow.LoadNodeRunByID(api.mustDB(), nodeJobRun.WorkflowNodeRunID, workflow.LoadRunOptions{
DisableDetailledNodeRun: true,
})
nodeRunP, err := workflow.LoadNodeRunByID(api.mustDB(), nodeJobRun.WorkflowNodeRunID, workflow.LoadRunOptions{DisableDetailledNodeRun: true})
if err != nil {
log.Warning(ctx, "postWorkflowJobStepStatusHandler> Unable to load node run for event: %v", err)
return nil
Expand Down
6 changes: 0 additions & 6 deletions sdk/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ import (
"time"
)

// These are constant for events about workflow runs
const (
EventSubsWorkflowRuns = "event:workflow:runs"
EventSubWorkflowRun = "event:workflow:run"
)

// Event represents a event from API
// Event is "create", "update", "delete"
// Status is "Waiting" "Building" "Success" "Fail" "Unknown", optional
Expand Down
36 changes: 22 additions & 14 deletions ui/src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { Store } from '@ngxs/store';
import { WorkflowNodeRun } from 'app/model/workflow.run.model';
import { WorkflowNodeRun, WorkflowRun } from 'app/model/workflow.run.model';
import { AsCodeEvent } from 'app/store/ascode.action';
import { UpdateMaintenance } from 'app/store/cds.action';
import cloneDeep from 'lodash-es/cloneDeep';
Expand Down Expand Up @@ -333,26 +333,34 @@ export class AppService {
this._workflowRunService
.getWorkflowRun(event.project_key, event.workflow_name, event.workflow_run_num)
.pipe(first())
.subscribe(wr => this._store.dispatch(new UpdateWorkflowRunList({ workflowRun: wr })));
.subscribe(wrkRun => this._store.dispatch(new UpdateWorkflowRunList({ workflowRun: wrkRun })));
}
break;
case EventType.RUN_WORKFLOW_NODE:
if (this.routeParams['number'] === event.workflow_run_num.toString()) {
// Refresh node run if user is listening on it
const wnr = this._store.selectSnapshot<WorkflowNodeRun>((state) => {
return state.workflow.workflowNodeRun;
});
let wnrEvent = <WorkflowNodeRun>event.payload;
if (wnr && wnr.id === wnrEvent.id) {
this._store.dispatch(
new GetWorkflowNodeRun({
projectKey: event.project_key,
workflowName: event.workflow_name,
num: event.workflow_run_num,
nodeRunID: wnr.id
}));
}

// Refresh workflow run if user is listening on it
const wr = this._store.selectSnapshot<WorkflowRun>((state) => state.workflow.workflowRun);
if (wr && wr.num === event.workflow_run_num) {
this._store.dispatch(new GetWorkflowRun(
{
projectKey: event.project_key, workflowName: event.workflow_name,
projectKey: event.project_key,
workflowName: event.workflow_name,
num: event.workflow_run_num
}));
let wnr = <WorkflowNodeRun>event.payload;
if (this.routeParams['nodeId'] && this.routeParams['nodeId'].toString() === wnr.id) {
this._store.dispatch(
new GetWorkflowNodeRun({
projectKey: event.project_key,
workflowName: event.workflow_name,
num: event.workflow_run_num,
nodeRunID: this.routeParams['nodeId']
}));
}
}
break;
}
Expand Down
22 changes: 9 additions & 13 deletions ui/src/app/model/workflow.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,20 +320,16 @@ export class Workflow {
for (let j = 0; j < n.triggers.length; j++) {
let t = n.triggers[j];
if (t.child_node.id === currentNodeID) {
if (workflowRun.version < 2) {
switch (n.type) {
case WNodeType.JOIN:
ancestors.push(...n.parents.map(p => p.parent_id));
break;
case WNodeType.FORK:
ancestors.push(...Workflow.getParentNodeIds(workflowRun, n.id));
break;
default:
ancestors.push(n.id);
switch (n.type) {
case WNodeType.JOIN:
ancestors.push(...n.parents.map(p => p.parent_id));
break;
case WNodeType.FORK:
ancestors.push(...Workflow.getParentNodeIds(workflowRun, n.id));
break;
default:
ancestors.push(n.id);
}
} else {
ancestors.push(n.id);
}
break loop;
}
}
Expand Down
1 change: 0 additions & 1 deletion ui/src/app/model/workflow.run.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export class WorkflowRun {
tags: Array<WorkflowRunTags>;
commits: Array<Commit>;
infos: Array<SpawnInfo>;
version: number;

// Useful for UI
duration: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Project } from 'app/model/project.model';
import { WNode, Workflow } from 'app/model/workflow.model';
import { WorkflowNodeRun, WorkflowRun } from 'app/model/workflow.run.model';
import { AutoUnsubscribe } from 'app/shared/decorator/autoUnsubscribe';
import { WorkflowState, WorkflowStateModel } from 'app/store/workflow.state';
import { WorkflowState } from 'app/store/workflow.state';
import { Subscription } from 'rxjs';

@Component({
Expand All @@ -28,7 +28,6 @@ export class WorkflowWNodeMenuEditComponent implements OnInit {

// Project that contains the workflow
@Input() project: Project;

@Input() node: WNode;
_noderun: WorkflowNodeRun;
@Input('noderun') set noderun(data: WorkflowNodeRun) {
Expand Down Expand Up @@ -57,9 +56,8 @@ export class WorkflowWNodeMenuEditComponent implements OnInit {
) { }

ngOnInit(): void {
this.storeSubscription = this._store.select(WorkflowState.getCurrent())
.subscribe((s: WorkflowStateModel) => {
this.workflow = s.workflow;
this.storeSubscription = this._store.select(WorkflowState.getWorkflow()).subscribe((w: Workflow) => {
this.workflow = w;
this.runnable = this.getCanBeRun();
this._cd.markForCheck();
});
Expand Down
Loading

0 comments on commit 454d726

Please sign in to comment.