Skip to content

Commit

Permalink
Fix out-of-memory error when building hundreds of pages
Browse files Browse the repository at this point in the history
  • Loading branch information
szimek committed Nov 23, 2017
1 parent 17848d7 commit 8ab36c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const _ = require(`lodash`)
const Promise = require(`bluebird`)
const os = require(`os`)

const { store, emitter } = require(`../../redux`)
const queryRunner = require(`./query-runner`)
Expand Down Expand Up @@ -90,8 +91,9 @@ const runQueriesForIds = ids => {
return Promise.resolve()
}
const state = store.getState()
return Promise.all(
ids.map(id => {
return Promise.map(
ids,
id => {
const pagesAndLayouts = [...state.pages, ...state.layouts]
const plObj = pagesAndLayouts.find(
pl => pl.path === id || `LAYOUT___${pl.id}` === id
Expand All @@ -100,7 +102,8 @@ const runQueriesForIds = ids => {
return queryRunner(plObj, state.components[plObj.component])
}
return null
})
},
{ concurrency: Math.min(os.cpus().length, 32) }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

const _ = require(`lodash`)
const chokidar = require(`chokidar`)
const os = require(`os`)

const { store } = require(`../../redux/`)
const { boundActionCreators } = require(`../../redux/actions`)
Expand Down Expand Up @@ -57,7 +58,11 @@ const runQueriesForComponent = componentPath => {
pages.map(p => p.path || p.id)
)
const component = store.getState().components[componentPath]
return Promise.all(pages.map(p => queryRunner(p, component)))
return Promise.map(
pages,
p => queryRunner(p, component),
{ concurrency: Math.min(os.cpus().length, 32) }
)
}

const getPagesForComponent = componentPath => {
Expand Down

0 comments on commit 8ab36c6

Please sign in to comment.