Skip to content

Commit

Permalink
Request v2 of upgrade path API, minimizes http requests and updates b…
Browse files Browse the repository at this point in the history
…uildUserVersion
  • Loading branch information
fasterthanlime committed Sep 7, 2016
1 parent 334da54 commit 961d389
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 28 deletions.
5 changes: 3 additions & 2 deletions appsrc/tasks/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import invariant from 'invariant'
import butler from '../util/butler'

export default async function apply (out, opts) {
const {buildId, globalMarket, cave, gameId, patchPath, signaturePath, outPath} = opts
const {buildId, buildUserVersion, globalMarket, cave, gameId, patchPath, signaturePath, outPath} = opts
invariant(typeof globalMarket === 'object', 'apply must have globalMarket')
invariant(typeof cave === 'object', 'apply must have cave')
invariant(gameId, 'apply must have gameId')
Expand All @@ -14,7 +14,8 @@ export default async function apply (out, opts) {
await butler.apply(opts)

const caveUpdate = {
buildId
buildId,
buildUserVersion
}
await globalMarket.saveEntity('caves', cave.id, caveUpdate, {wait: true})

Expand Down
1 change: 1 addition & 0 deletions appsrc/tasks/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ async function downloadPatches (out, opts) {
cave,
gameId,
buildId: patch.entry.id,
buildUserVersion: patch.entry.userVersion,
patchPath: patch.patchPath,
signaturePath: patch.signaturePath,
outPath: cavePath,
Expand Down
26 changes: 2 additions & 24 deletions appsrc/tasks/find-upgrade-path.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@

import Promise from 'bluebird'
import invariant from 'invariant'

import client from '../util/api'
import mklog from '../util/log'
const log = mklog('tasks/find-upgrade-path')

import needle from '../promised/needle'
import {each} from 'underline'

async function getBuildSize (api, downloadKey, uploadId, buildId) {
const response = await api.downloadBuild(downloadKey, uploadId, buildId)
const res = await needle.headAsync(response.patch.url, {})
return {
id: buildId,
patchSize: parseInt(res.headers['content-length'], 10)
}
}

async function extendPath (upgradePath, api, downloadKey, uploadId) {
const extended = await Promise.map(upgradePath, (buildId) =>
getBuildSize(api, downloadKey, uploadId, buildId)
)
return extended
}

export default async function start (out, opts) {
const {credentials, market, upload, downloadKey, gameId, currentBuildId} = opts
invariant(typeof gameId === 'number', 'find-upgrade-path has gameId')
Expand All @@ -43,13 +25,9 @@ export default async function start (out, opts) {
const response = await api.findUpgrade(downloadKey, upload.id, currentBuildId)

let upgradePath = response.upgradePath
if (!response.extended) {
// current build is the 1st element of the upgrade path
upgradePath.shift()

log(opts, `Extending short upgrade path: ${JSON.stringify(upgradePath, 0, 2)}`)
upgradePath = await extendPath(upgradePath, api, downloadKey, upload.id)
}
// current build is the 1st element of the upgrade path
upgradePath.shift()

log(opts, `Got upgrade path: ${JSON.stringify(upgradePath, 0, 2)}`)

Expand Down
4 changes: 2 additions & 2 deletions appsrc/util/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ export class AuthenticatedClient {

async findUpgrade (downloadKey, uploadId, currentBuildId) {
if (downloadKey) {
return await this.request('get', `/download-key/${downloadKey.id}/upgrade/${uploadId}/${currentBuildId}`)
return await this.request('get', `/download-key/${downloadKey.id}/upgrade/${uploadId}/${currentBuildId}?v=2`)
} else {
return await this.request('get', `/upload/${uploadId}/upgrade/${currentBuildId}`)
return await this.request('get', `/upload/${uploadId}/upgrade/${currentBuildId}?v=2`)
}
}

Expand Down

0 comments on commit 961d389

Please sign in to comment.