Skip to content

Commit

Permalink
chrome(sqip): restructure debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger committed Apr 21, 2019
1 parent 29677ce commit f5dfde4
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions packages/gatsby-transformer-sqip/src/generate-sqip.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,19 @@ module.exports = async function generateSqip(options) {
const cacheKey = `sqip-${name}-${optionsHash}`
const cachePath = resolve(cacheDir, `${name}-${optionsHash}.svg`)

debug(`Request preview generation for ${name}-${optionsHash}`)

return queue.add(async () => {
let primitiveData = await cache.get(cacheKey)

debug(
`Adding preview generation request to queue for ${name}-${optionsHash}`,
{
sqipOptions,
hasCache: !!primitiveData,
}
)
debug(`Executing preview generation request for ${name}-${optionsHash}`)

if (!primitiveData) {
let svg
debug("Checking for path: " + cachePath)

if (await exists(cachePath)) {
debug(
`Primitive result file already exists of ${name}-${optionsHash} (${cachePath})`
`Primitive result file already exists for ${name}-${optionsHash} (${cachePath})`
)
const svgBuffer = await readFile(cachePath)
svg = svgBuffer.toString()
Expand All @@ -74,7 +70,7 @@ module.exports = async function generateSqip(options) {
svg = result.final_svg

await writeFile(cachePath, svg)
debug(`Wrote primitive result file to disk of ${name}-${optionsHash}`)
debug(`Wrote primitive result file to disk for ${name}-${optionsHash}`)
}

primitiveData = {
Expand All @@ -83,6 +79,8 @@ module.exports = async function generateSqip(options) {
}

await cache.set(cacheKey, primitiveData)
} else {
debug(`Cache found for ${name}-${optionsHash}`)
}

return primitiveData
Expand Down

0 comments on commit f5dfde4

Please sign in to comment.