Skip to content

Commit

Permalink
feat(logging): Add more context to batched get operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedikt Rötsch committed Dec 18, 2017
1 parent 0c8dd85 commit 63b21d0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/get/get-full-source-space.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function pagedGet ({space, method, skip = 0, aggregatedResponse = null, query =
}
const page = Math.ceil(skip / pageLimit) + 1
const pages = Math.ceil(response.total / pageLimit)
logEmitter.emit('info', `Fetched page ${page} of ${pages}`)
logEmitter.emit('info', `Fetched ${aggregatedResponse.items.length} of ${response.total} items (Page ${page}/${pages})`)
if (skip + pageLimit <= response.total) {
return pagedGet({space, method, skip: skip + pageLimit, aggregatedResponse, query})
}
Expand Down
21 changes: 16 additions & 5 deletions lib/get/get-outdated-destination-content.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import Promise from 'bluebird'
import { logEmitter } from '../utils/logging'

const BATCH_CHAR_LIMIT = 1990
const BATCH_SIZE_LIMIT = 100

const METHODS = {
contentTypes: { name: 'content types', method: 'getContentTypes' },
locales: { name: 'locales', method: 'getLocales' },
entries: { name: 'entries', method: 'getEntries' },
assets: { name: 'assets', method: 'getAssets' }
}

/**
* Gets content from a space which will have content copied to it, based on a
* collection of existing content.
Expand Down Expand Up @@ -30,11 +38,11 @@ export default function getOutdatedDestinationContent ({

if (!skipContentModel) {
const contentTypeIds = sourceContent.contentTypes.map((e) => e.sys.id)
result.contentTypes = batchedIdQuery(space, 'getContentTypes', contentTypeIds)
result.contentTypes = batchedIdQuery(space, 'contentTypes', contentTypeIds)

if (!skipLocales) {
const localeIds = sourceContent.locales.map((e) => e.sys.id)
result.locales = batchedIdQuery(space, 'getLocales', localeIds)
result.locales = batchedIdQuery(space, 'locales', localeIds)
}
}

Expand All @@ -44,8 +52,8 @@ export default function getOutdatedDestinationContent ({

const entryIds = sourceContent.entries.map((e) => e.sys.id)
const assetIds = sourceContent.assets.map((e) => e.sys.id)
result.entries = batchedIdQuery(space, 'getEntries', entryIds)
result.assets = batchedIdQuery(space, 'getAssets', assetIds)
result.entries = batchedIdQuery(space, 'entries', entryIds)
result.assets = batchedIdQuery(space, 'assets', assetIds)
result.webhooks = []

return Promise.props(result)
Expand All @@ -54,14 +62,17 @@ export default function getOutdatedDestinationContent ({
})
}

function batchedIdQuery (space, method, ids) {
function batchedIdQuery (space, type, ids) {
const method = METHODS[type].method
const entityTypeName = METHODS[type].name
return Promise.reduce(getIdBatches(ids), (fullResponse, batch) => {
return space[method]({
'sys.id[in]': batch,
limit: batch.split(',').length
})
.then((response) => {
fullResponse = fullResponse.concat(response.items)
logEmitter.emit('info', `Fetched ${fullResponse.length} of ${response.total} ${entityTypeName}`)
return fullResponse
})
}, [])
Expand Down
1 change: 0 additions & 1 deletion lib/push/push-to-space.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ export default function pushToSpace ({
const teardownTaskListeners = logToTaskOutput(task)

let contentTypesWithEditorInterface = ctx.data.contentTypes.map((contentType) => {
// @todo -> potential bug: only exports one editorinterface, multiple possible?
for (let editorInterface of sourceContent.editorInterfaces) {
if (editorInterface.sys.contentType.sys.id === contentType.sys.id) {
return ctx.space.getEditorInterfaceForContentType(contentType.sys.id)
Expand Down

0 comments on commit 63b21d0

Please sign in to comment.