Skip to content

Commit 9b66f89

Browse files
committed
fix(Deployment): refactor Deployment fields to fix perf issues
This corresponds to changes in ibi-group/datatools-server#310 fix #574
1 parent af00ed8 commit 9b66f89

File tree

14 files changed

+79
-45
lines changed

14 files changed

+79
-45
lines changed

__tests__/test-utils/mock-data/manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function makeMockDeployment (
5555
osmExtractUrl: null,
5656
otpCommit: null,
5757
otpVersion: null,
58-
project,
58+
projectId: project.id,
5959
projectBounds: {east: 0, west: 0, north: 0, south: 0},
6060
r5: false,
6161
r5Version: null,

lib/manager/actions/deployments.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export function deployToTarget (deployment: Deployment, target: string) {
9393
} else {
9494
// If the deployment request succeeded, start monitoring the job.
9595
dispatch(startJobMonitor())
96-
dispatch(fetchProjectDeployments(deployment.project.id))
96+
dispatch(fetchProjectDeployments(deployment.projectId))
9797
}
9898
})
9999
.then(json => {
@@ -155,12 +155,12 @@ export function fetchDeploymentAndProject (id: string) {
155155

156156
export function deleteDeployment (deployment: Deployment & { isCreating?: boolean }) {
157157
return function (dispatch: dispatchFn, getState: getStateFn) {
158-
const {id, isCreating, project} = deployment
158+
const {id, isCreating, projectId} = deployment
159159
if (isCreating) {
160-
return dispatch(fetchProjectDeployments(project.id))
160+
return dispatch(fetchProjectDeployments(projectId))
161161
}
162162
return dispatch(secureFetch(`${DEPLOYMENT_URL}/${id}`, 'delete'))
163-
.then((res) => dispatch(fetchProjectDeployments(project.id)))
163+
.then((res) => dispatch(fetchProjectDeployments(projectId)))
164164
}
165165
}
166166

@@ -191,7 +191,7 @@ export function saveDeployment (
191191
dispatch(savingDeployment())
192192
return dispatch(secureFetch(DEPLOYMENT_URL, 'post', props))
193193
.then(response => response.json())
194-
.then(deployment => dispatch(fetchProjectDeployments(deployment.project.id)))
194+
.then(deployment => dispatch(fetchProjectDeployments(deployment.projectId)))
195195
}
196196
}
197197

lib/manager/components/CurrentDeploymentPanel.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,21 @@ import { getActiveInstanceCount, getServerForId } from '../util/deployment'
1515
import DeploymentPreviewButton from './DeploymentPreviewButton'
1616
import EC2InstanceCard from '../../common/components/EC2InstanceCard'
1717

18-
import type { Deployment, DeploySummary, EC2InstanceSummary, OtpServer, ServerJob } from '../../types'
18+
import type {
19+
Deployment,
20+
DeploySummary,
21+
EC2InstanceSummary,
22+
OtpServer,
23+
Project,
24+
ServerJob
25+
} from '../../types'
1926

2027
type Props = {
2128
deployJobs: Array<ServerJob>,
2229
deployment: Deployment,
2330
downloadBuildArtifact: typeof deploymentActions.downloadBuildArtifact,
2431
fetchDeployment: typeof deploymentActions.fetchDeployment,
32+
project: Project,
2533
server: ?OtpServer,
2634
terminateEC2InstanceForDeployment: typeof deploymentActions.terminateEC2InstanceForDeployment
2735
}
@@ -35,6 +43,12 @@ export default class CurrentDeploymentPanel extends Component<Props, State> {
3543
activeSummaryIndex: 0
3644
}
3745

46+
componentDidMount () {
47+
// Fetch single deployment. This JSON response will contain the #ec2Instances
48+
// field, which does not come with this field (to prevent a very slow response).
49+
this.props.fetchDeployment(this.props.deployment.id)
50+
}
51+
3852
componentWillReceiveProps (nextProps: Props) {
3953
// If status message changes while deployment job is in progress, re-fetch
4054
// deployment to update EC2 instance status.
@@ -55,7 +69,7 @@ export default class CurrentDeploymentPanel extends Component<Props, State> {
5569
if (this.props.server) return this.props.server
5670
const deployJob = this._getDeployJob()
5771
const serverId = deployJob && deployJob.serverId
58-
return getServerForId(serverId, this.props.deployment.project)
72+
return getServerForId(serverId, this.props.project)
5973
}
6074

6175
handleDecrementSummary = () => {
@@ -84,11 +98,12 @@ export default class CurrentDeploymentPanel extends Component<Props, State> {
8498
}
8599

86100
render () {
87-
const { deployJobs, deployment } = this.props
101+
const { deployJobs, deployment, project } = this.props
88102
const { activeSummaryIndex } = this.state
89103
const deployJob = this._getDeployJob()
90104
const server = this._getServer()
91105
const ec2Info = server && server.ec2Info
106+
console.log(server, ec2Info, deployment)
92107
const hasPreviouslyDeployed = deployment.deployJobSummaries.length > 0
93108
return (
94109
<Panel header={<h3><Icon type='server' /> Deployment Summary</h3>}>
@@ -137,13 +152,14 @@ export default class CurrentDeploymentPanel extends Component<Props, State> {
137152
}
138153
{hasPreviouslyDeployed
139154
? <DeployJobSummary
140-
summary={deployment.deployJobSummaries[activeSummaryIndex]}
155+
deployment={deployment}
141156
downloadBuildArtifact={this.props.downloadBuildArtifact}
157+
project={project}
142158
server={server}
143-
deployment={deployment} />
159+
summary={deployment.deployJobSummaries[activeSummaryIndex]} />
144160
: 'No current deployment found'
145161
}
146-
{ec2Info || deployment.ec2Instances.length > 0
162+
{ec2Info // If has EC2 info, show EC2 instances box.
147163
? <div>
148164
<h4>
149165
EC2 instances ({getActiveInstanceCount(deployment.ec2Instances)} active)
@@ -154,7 +170,7 @@ export default class CurrentDeploymentPanel extends Component<Props, State> {
154170
<Icon type='refresh' />
155171
</Button>
156172
</h4>
157-
{deployment.ec2Instances.length > 0
173+
{deployment.ec2Instances
158174
? <div style={{ height: '200px', overflow: 'scroll', paddingRight: '10px' }}>
159175
{deployment.ec2Instances.map(instance => {
160176
return (
@@ -180,6 +196,7 @@ export default class CurrentDeploymentPanel extends Component<Props, State> {
180196
class DeployJobSummary extends Component<{
181197
deployment: Deployment,
182198
downloadBuildArtifact: typeof deploymentActions.downloadBuildArtifact,
199+
project: Project,
183200
server: ?OtpServer,
184201
summary: ?DeploySummary
185202
}> {
@@ -213,7 +230,7 @@ class DeployJobSummary extends Component<{
213230
}
214231

215232
render () {
216-
const {deployment, server, summary} = this.props
233+
const {deployment, project, server, summary} = this.props
217234
const serverLabel = this._getLabelForServer(server, deployment)
218235
let deploymentType = 'unknown'
219236
if (server) {
@@ -265,7 +282,10 @@ class DeployJobSummary extends Component<{
265282
</Button>
266283
</ButtonToolbar>
267284
<div style={{ margin: '20px 0' }}>
268-
<DeploymentPreviewButton block deployment={deployment} />
285+
<DeploymentPreviewButton
286+
block
287+
deployment={deployment}
288+
project={project} />
269289
</div>
270290
</div>
271291
)

lib/manager/components/DeploymentConfirmModal.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ import {getFeedNames, versionHasExpired} from '../util/version'
1212
import polygon from 'turf-polygon'
1313
import area from '@turf/area'
1414

15-
import type {Deployment, SummarizedFeedVersion} from '../../types'
15+
import type {Deployment, Project, SummarizedFeedVersion} from '../../types'
1616

1717
type Props = {
1818
deployToTarget: typeof deploymentActions.deployToTarget,
1919
deployment: Deployment,
2020
oldDeployment: ?Deployment,
2121
onClose: () => void,
22+
project: Project,
2223
target: string
2324
}
2425

@@ -42,7 +43,7 @@ export default class DeploymentConfirmModal extends Component<Props, State> {
4243

4344
render () {
4445
const {Body, Footer, Header, Title} = Modal
45-
const {deployment, oldDeployment, target} = this.props
46+
const {deployment, oldDeployment, project, target} = this.props
4647
const {isDeployed} = this.state
4748
const isMissingFeeds = deployment.feedVersions.length === 0
4849
const isMissingBounds = !deployment.projectBounds
@@ -57,7 +58,7 @@ export default class DeploymentConfirmModal extends Component<Props, State> {
5758
}
5859
const deploymentIsDisabled = isDeployed || boundsTooLarge || isMissingBounds || isMissingFeeds
5960
const expiredFeeds: Array<SummarizedFeedVersion> = deployment.feedVersions.filter(versionHasExpired)
60-
const server = getServerForId(target, deployment.project)
61+
const server = getServerForId(target, project)
6162
return (
6263
<Modal show onHide={this._onClose}>
6364
<Header>

lib/manager/components/DeploymentPreviewButton.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@ import Icon from '@conveyal/woonerf/components/icon'
44
import React, {Component} from 'react'
55
import {Button, Tooltip, OverlayTrigger} from 'react-bootstrap'
66

7-
import type {Deployment} from '../../types'
7+
import type {Deployment, Project} from '../../types'
88

99
type Props = {
10-
deployment: Deployment
10+
deployment: Deployment,
11+
project: Project
1112
}
1213

1314
export default class DeploymentPreviewButton extends Component<Props> {
1415
render () {
15-
const { deployment, ...buttonProps } = this.props
16-
const { id, deployedTo, project, projectBounds } = deployment
16+
const { deployment, project, ...buttonProps } = this.props
17+
const { id, deployedTo, projectBounds } = deployment
1718
if (!deployedTo) {
1819
// Deployment has not been deployed to a server, do not render button.
1920
return null
2021
}
21-
if (!deployment.project.otpServers) {
22+
if (!project.otpServers) {
2223
console.warn(`No otp servers defined for project`)
2324
return null
2425
}

lib/manager/components/DeploymentVersionsTable.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {ManagerUserState} from '../../types/reducers'
1515
type Props = {
1616
deleteFeedVersion: typeof deploymentActions.deleteFeedVersion,
1717
deployment: Deployment,
18+
project: Project,
1819
updateVersionForFeedSource: typeof deploymentActions.updateVersionForFeedSource,
1920
user: ManagerUserState,
2021
versions: Array<SummarizedFeedVersion>
@@ -24,7 +25,14 @@ export default class DeploymentVersionsTable extends Component<Props> {
2425
messages = getComponentMessages('DeploymentVersionsTable')
2526

2627
render () {
27-
const {deployment, deleteFeedVersion, versions, updateVersionForFeedSource, user} = this.props
28+
const {
29+
deployment,
30+
deleteFeedVersion,
31+
project,
32+
versions,
33+
updateVersionForFeedSource,
34+
user
35+
} = this.props
2836
return (
2937
<Table striped hover fill>
3038
<thead>
@@ -47,7 +55,7 @@ export default class DeploymentVersionsTable extends Component<Props> {
4755
return <FeedVersionTableRow
4856
feedSource={version.feedSource}
4957
version={version}
50-
project={deployment.project}
58+
project={project}
5159
deployment={deployment}
5260
key={version.id}
5361
user={user}

lib/manager/components/DeploymentViewer.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ export default class DeploymentViewer extends Component<Props, State> {
256256
{east: 10, north: 10, west: -10, south: -10}
257257
const boundsTooLarge = east - west > BOUNDS_LIMIT || north - south > BOUNDS_LIMIT
258258
const bounds = this._getBounds()
259-
const serverDeployedTo = getServerDeployedTo(deployment)
259+
const serverDeployedTo = getServerDeployedTo(deployment, project)
260260
const isWatchingDeployment = user.subscriptions && user.subscriptions.hasFeedSubscription(
261261
project.id,
262262
deployment.id,
@@ -279,6 +279,7 @@ export default class DeploymentViewer extends Component<Props, State> {
279279
deployment={deployment}
280280
oldDeployment={oldDeployment}
281281
onClose={this._onCloseModal}
282+
project={project}
282283
target={target} />
283284
}
284285
<Row>
@@ -428,10 +429,11 @@ export default class DeploymentViewer extends Component<Props, State> {
428429
</p>
429430
: <DeploymentVersionsTable
430431
deleteFeedVersion={deleteFeedVersion}
432+
deployment={deployment}
433+
project={project}
431434
updateVersionForFeedSource={updateVersionForFeedSource}
432435
user={user}
433-
versions={versions}
434-
deployment={deployment} />
436+
versions={versions} />
435437
}
436438
</ListGroup>
437439
</Panel>
@@ -440,11 +442,12 @@ export default class DeploymentViewer extends Component<Props, State> {
440442
{/* Current deployment panel */}
441443
<CurrentDeploymentPanel
442444
deployJobs={deployJobs}
443-
server={serverDeployedTo}
445+
deployment={deployment}
444446
downloadBuildArtifact={this.props.downloadBuildArtifact}
445447
fetchDeployment={this.props.fetchDeployment}
446-
terminateEC2InstanceForDeployment={this.props.terminateEC2InstanceForDeployment}
447-
deployment={deployment} />
448+
project={project}
449+
server={serverDeployedTo}
450+
terminateEC2InstanceForDeployment={this.props.terminateEC2InstanceForDeployment} />
448451
{/* Configurations panel */}
449452
<Panel header={<h3><Icon type='cog' /> OTP Configuration</h3>}>
450453
<ListGroup fill>
@@ -601,7 +604,7 @@ class CustomConfig extends Component<{
601604
disabled={!this.state[name] || !validJSON}
602605
onClick={this._onSaveConfig}>Save</Button>
603606
: <LinkContainer
604-
to={`/project/${deployment.project.id}/settings/deployment`}>
607+
to={`/project/${deployment.projectId}/settings/deployment`}>
605608
<Button bsSize='xsmall'>
606609
<Icon type='pencil' /> Edit
607610
</Button>

lib/manager/components/DeploymentsPanel.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ class DeploymentListItem extends Component<RowProps> {
252252
}
253253

254254
render () {
255-
const {deployment} = this.props
256-
const server = getServerDeployedTo(deployment)
255+
const {deployment, project} = this.props
256+
const server = getServerDeployedTo(deployment, project)
257257
const na = (<span className='deployment-na'>N/A</span>)
258258
return (
259259
<tr className={this._isPinned() ? 'pinned-deployment' : ''}>
@@ -263,7 +263,7 @@ class DeploymentListItem extends Component<RowProps> {
263263
value={deployment.name}
264264
rejectEmptyValue
265265
onChange={this._onChangeName}
266-
link={`/project/${deployment.project.id}/deployments/${deployment.id}`}
266+
link={`/project/${deployment.projectId}/deployments/${deployment.id}`}
267267
/>
268268
</td>
269269
<td>

lib/manager/components/ProjectViewer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ export default class ProjectViewer extends Component<Props, State> {
6767
} else {
6868
browserHistory.push(`/project/${id}/${key}`)
6969
}
70-
if (key === 'deployments' && !deployments) {
71-
this._fetchDeployments()
72-
}
70+
// if (key === 'deployments' && !deployments) {
71+
// this._fetchDeployments()
72+
// }
7373
}
7474

7575
shouldComponentUpdate (newProps: Props, nextState: State) {

lib/manager/components/version/FeedVersionNavigator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ export default class FeedVersionNavigator extends Component<Props, State> {
228228
<ButtonGroup>
229229
{isModuleEnabled('deployment') && deploymentForVersion
230230
? <DeploymentPreviewButton
231-
deployment={deploymentForVersion}>
231+
deployment={deploymentForVersion}
232+
project={project}>
232233
View deployment {version && version.id}
233234
</DeploymentPreviewButton>
234235
: null

0 commit comments

Comments
 (0)