You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Gatsby v3 we were able to add gatsby images from a mongodb in gastby-node.js with similar code to that shown below. However we want to use Deferred Static Generation and i'm concerned that this method will try to make all the images in one loop (and creating the images is the biggest performance issue for this particular site - there's a lot!). What is the suggested method to employ, or will this code still allow the actual image creation to be deferred?
exports.sourceNodes=asynchelpers=>{const{
actions,
cache,
createNodeId,
getNodesByType,
store,
reporter,}=helpersconst{ createNode }=actionsconstimageDownloads=[]letsubmissions=getNodesByType("mongodbSubmissions")// profile images:submissions.forEach(node=>{// for each statement get about: image and statement: imagenode.statements&&node.statements.forEach(item=>{// get profile imageif(item.image){constimageUrl=`${imageUrlRoot}${item.image}`// reporter.info(`statement: ${imageUrl}`)imageDownloads.push(createRemoteFileNode({url: imageUrl,
store,
cache,
createNode,
createNodeId,
reporter,}).then(asyncresult=>{if(!result){returnreporter.warn(`Could not download ${imageUrl}`)}// // Checks to see the actual mime type of the cached fileconstmagicResult=awaitnewPromise((resolve,reject)=>{magic.detectFile(result.absolutePath,(err,r)=>{if(err){reject(r)}resolve(r)})}).then(r=>r)if(magicResult!==result.internal.mediaType){returnreporter.warn(`Something weird with the mime types ${imageUrl}`,)}item.imageFile___NODE=result.id}).catch(err=>{reporter.warn(err)}),)// imagedownloads push})// statements forEach}})// submissions forEachreturnPromise.all(imageDownloads)}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In Gatsby v3 we were able to add gatsby images from a mongodb in gastby-node.js with similar code to that shown below. However we want to use Deferred Static Generation and i'm concerned that this method will try to make all the images in one loop (and creating the images is the biggest performance issue for this particular site - there's a lot!). What is the suggested method to employ, or will this code still allow the actual image creation to be deferred?
Beta Was this translation helpful? Give feedback.
All reactions