Skip to content

Commit

Permalink
make job objects smaller
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Jan 18, 2020
1 parent 6342f4d commit 7a2a163
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 265 deletions.
104 changes: 24 additions & 80 deletions packages/gatsby-plugin-sharp/src/__tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Object {
"base64": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAAH6ji2bAAAACXBIWXMAAAPoAAAD6AG1e1JrAAABk0lEQVQ4y7VUy07DMBDsf9IDhcauaVM4IajUIuALOFRI/R24wB8AgkpInJKI9ME5zDi24rx5HjZKvOP17Hg2neh8nNjo8CGESGL7sbpwMvrlaepriF4J3dQLMlsXvzbVFCKHLJ3J8+5PRxqlF0OzleFLkSG7Xrp4faiyRaI/Lgs13QhNVB5uCUyUTDyUloidvkjezvyMEB8B4uZkqAHCiR44bYtCcecSirD5XQDmIGzVjOrEiJo4fhvY2jWTG3C6g/TLmZ+8VwEJekWy20+loUSzA5kDp15BKJmXhmD6Iqcjtep5eSArk0ZQPPpqPNAaWiBpbKt0pLgEU2xuIOewTh7rmFWFRH9/M78uaG8yNuox4oYbbrQEhaI4HKEh7mvfS2OE98WR0r6P26zj2ofW5rWowlzY2WduAQxZ14odmNZuMWA0h6wo5pplDxj+MrgnqDM3W32E/QYNxaxN2f7ztNx6qWUCOC3H+F/Y35EU2XCw3QkGhBrHX/WXLbwG4wewoAwMst84t/0jH4ZG36DFLv9m7E/1HjvIa/canAAAAABJRU5ErkJggg==",
"height": 100,
"originalName": undefined,
"src": "/static/1234/a2779/test.png",
"srcSet": "/static/1234/a2779/test.png 1x",
"src": "/static/1234/2f4e8/test.png",
"srcSet": "/static/1234/2f4e8/test.png 1x",
"tracedSVG": undefined,
"width": 100,
}
Expand All @@ -28,15 +28,15 @@ Object {
"aspectRatio": 1,
"base64": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAAH6ji2bAAAACXBIWXMAAAPoAAAD6AG1e1JrAAABk0lEQVQ4y7VUy07DMBDsf9IDhcauaVM4IajUIuALOFRI/R24wB8AgkpInJKI9ME5zDi24rx5HjZKvOP17Hg2neh8nNjo8CGESGL7sbpwMvrlaepriF4J3dQLMlsXvzbVFCKHLJ3J8+5PRxqlF0OzleFLkSG7Xrp4faiyRaI/Lgs13QhNVB5uCUyUTDyUloidvkjezvyMEB8B4uZkqAHCiR44bYtCcecSirD5XQDmIGzVjOrEiJo4fhvY2jWTG3C6g/TLmZ+8VwEJekWy20+loUSzA5kDp15BKJmXhmD6Iqcjtep5eSArk0ZQPPpqPNAaWiBpbKt0pLgEU2xuIOewTh7rmFWFRH9/M78uaG8yNuox4oYbbrQEhaI4HKEh7mvfS2OE98WR0r6P26zj2ofW5rWowlzY2WduAQxZ14odmNZuMWA0h6wo5pplDxj+MrgnqDM3W32E/QYNxaxN2f7ztNx6qWUCOC3H+F/Y35EU2XCw3QkGhBrHX/WXLbwG4wewoAwMst84t/0jH4ZG36DFLv9m7E/1HjvIa/canAAAAABJRU5ErkJggg==",
"density": 72,
"originalImg": "/static/1234/a2779/test.png",
"originalImg": "/static/1234/2f4e8/test.png",
"originalName": undefined,
"presentationHeight": 100,
"presentationWidth": 100,
"sizes": "(max-width: 100px) 100vw, 100px",
"src": "/static/1234/a2779/test.png",
"srcSet": "/static/1234/2d2c2/test.png 25w,
/static/1234/84325/test.png 50w,
/static/1234/a2779/test.png 100w",
"src": "/static/1234/2f4e8/test.png",
"srcSet": "/static/1234/e3e32/test.png 25w,
/static/1234/281bc/test.png 50w,
/static/1234/2f4e8/test.png 100w",
"srcSetType": "image/png",
"tracedSVG": undefined,
}
Expand All @@ -47,13 +47,13 @@ Object {
"aspectRatio": 1,
"base64": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAACXBIWXMAAAsSAAALEgHS3X78AAABKklEQVQ4y8WUy07DMBBFrwMpr4aybjepUeqIFd/CAgmJsuIHgWXVL+Gx4C3xCdQJnpm0UDJNAQnVuouMM8dzY4+DcoA/C/8Fe9bv4ABMMpQOZc5yFPqfwEUQY499jHoY9/BsKQyTRTNMyzu8WAwTbBnI2DY438XbPr0qFsFCvlrkMTERYFgRL3HYUvh5OMdpQqkbBtPC9NDiINQPCZM6LGVvUzIpwNch4V5EGxHS/DeYtjfHZbcyXB8yGfaPimcafLEMHqmw2L5OsWkUUuY6Ee5V28WUP25TXjwPS3iWUFnfcFQPFna98rlmSGL4IOZucQvgT76Po53qeOTYTtp4qpFKe/qM29PhJsVVl3SXsluntLfS7rPvn10MP1Aau+lKBuA9I/kV/AyW6gNTIWTuA/r8lQAAAABJRU5ErkJggg==",
"density": 72,
"originalImg": "/static/1234/c616f/test.png",
"originalImg": "/static/1234/62ab9/test.png",
"originalName": undefined,
"presentationHeight": 100,
"presentationWidth": 100,
"sizes": "(max-width: 100px) 100vw, 100px",
"src": "/static/1234/c616f/test.png",
"srcSet": "/static/1234/c616f/test.png 100w",
"src": "/static/1234/62ab9/test.png",
"srcSet": "/static/1234/62ab9/test.png 100w",
"srcSetType": "image/png",
"tracedSVG": undefined,
}
Expand All @@ -64,13 +64,13 @@ Object {
"aspectRatio": 1,
"base64": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAACXBIWXMAAAsSAAALEgHS3X78AAABKklEQVQ4y8WUy07DMBBFrwMpr4aybjepUeqIFd/CAgmJsuIHgWXVL+Gx4C3xCdQJnpm0UDJNAQnVuouMM8dzY4+DcoA/C/8Fe9bv4ABMMpQOZc5yFPqfwEUQY499jHoY9/BsKQyTRTNMyzu8WAwTbBnI2DY438XbPr0qFsFCvlrkMTERYFgRL3HYUvh5OMdpQqkbBtPC9NDiINQPCZM6LGVvUzIpwNch4V5EGxHS/DeYtjfHZbcyXB8yGfaPimcafLEMHqmw2L5OsWkUUuY6Ee5V28WUP25TXjwPS3iWUFnfcFQPFna98rlmSGL4IOZucQvgT76Po53qeOTYTtp4qpFKe/qM29PhJsVVl3SXsluntLfS7rPvn10MP1Aau+lKBuA9I/kV/AyW6gNTIWTuA/r8lQAAAABJRU5ErkJggg==",
"density": 72,
"originalImg": "/static/1234/c616f/test.png",
"originalImg": "/static/1234/62ab9/test.png",
"originalName": undefined,
"presentationHeight": 100,
"presentationWidth": 100,
"sizes": "(max-width: 100px) 100vw, 100px",
"src": "/static/1234/c616f/test.png",
"srcSet": "/static/1234/c616f/test.png 100w",
"src": "/static/1234/62ab9/test.png",
"srcSet": "/static/1234/62ab9/test.png 100w",
"srcSetType": "image/png",
"tracedSVG": undefined,
}
Expand All @@ -96,24 +96,10 @@ exports[`gatsby-plugin-sharp queueImageResizing with createJob file name works w
"operations": Array [
Object {
"args": Object {
"base64": true,
"duotone": false,
"grayscale": false,
"jpegProgressive": true,
"jpegQuality": null,
"maxWidth": 800,
"pathPrefix": "",
"pngCompressionLevel": 9,
"pngCompressionSpeed": 4,
"pngQuality": null,
"quality": 50,
"sizeByPixelDensity": false,
"toFormat": "png",
"toFormatBase64": "",
"webpQuality": null,
"width": 3,
},
"outputPath": "9b610/spaces and '\\"@#$%^&,.png",
"outputPath": "2cee9/spaces and '\\"@#$%^&,.png",
},
],
"pluginOptions": Object {
Expand Down Expand Up @@ -151,24 +137,10 @@ exports[`gatsby-plugin-sharp queueImageResizing with createJob should round heig
"operations": Array [
Object {
"args": Object {
"base64": true,
"duotone": false,
"grayscale": false,
"jpegProgressive": true,
"jpegQuality": null,
"maxWidth": 800,
"pathPrefix": "",
"pngCompressionLevel": 9,
"pngCompressionSpeed": 4,
"pngQuality": null,
"quality": 50,
"sizeByPixelDensity": false,
"toFormat": "png",
"toFormatBase64": "",
"webpQuality": null,
"width": 3,
},
"outputPath": "9b610/test.png",
"outputPath": "2cee9/test.png",
},
],
"pluginOptions": Object {
Expand Down Expand Up @@ -206,24 +178,10 @@ exports[`gatsby-plugin-sharp queueImageResizing with createJobV2 file name works
"operations": Array [
Object {
"args": Object {
"base64": true,
"duotone": false,
"grayscale": false,
"jpegProgressive": true,
"jpegQuality": null,
"maxWidth": 800,
"pathPrefix": "",
"pngCompressionLevel": 9,
"pngCompressionSpeed": 4,
"pngQuality": null,
"quality": 50,
"sizeByPixelDensity": false,
"toFormat": "png",
"toFormatBase64": "",
"webpQuality": null,
"width": 3,
},
"outputPath": "9b610/spaces and '\\"@#$%^&,.png",
"outputPath": "2cee9/spaces and '\\"@#$%^&,.png",
},
],
"pluginOptions": Object {
Expand Down Expand Up @@ -260,24 +218,10 @@ exports[`gatsby-plugin-sharp queueImageResizing with createJobV2 should round he
"operations": Array [
Object {
"args": Object {
"base64": true,
"duotone": false,
"grayscale": false,
"jpegProgressive": true,
"jpegQuality": null,
"maxWidth": 800,
"pathPrefix": "",
"pngCompressionLevel": 9,
"pngCompressionSpeed": 4,
"pngQuality": null,
"quality": 50,
"sizeByPixelDensity": false,
"toFormat": "png",
"toFormatBase64": "",
"webpQuality": null,
"width": 3,
},
"outputPath": "9b610/test.png",
"outputPath": "2cee9/test.png",
},
],
"pluginOptions": Object {
Expand Down Expand Up @@ -323,8 +267,8 @@ Object {
"base64": undefined,
"height": 100,
"originalName": undefined,
"src": "/static/1234/c616f/test.png",
"srcSet": "/static/1234/c616f/test.png 1x",
"src": "/static/1234/62ab9/test.png",
"srcSet": "/static/1234/62ab9/test.png 1x",
"tracedSVG": "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='100'%20height='100'%3e%3cpath%20d='M41%2024c-18%207-24%2029-11%2043%2015%2017%2044%208%2046-15%201-19-17-34-35-28'%20fill='red'%20fill-rule='evenodd'/%3e%3c/svg%3e",
"width": 100,
}
Expand All @@ -335,15 +279,15 @@ Object {
"aspectRatio": 1,
"base64": undefined,
"density": 72,
"originalImg": "/static/1234/c616f/test.png",
"originalImg": "/static/1234/62ab9/test.png",
"originalName": undefined,
"presentationHeight": 100,
"presentationWidth": 100,
"sizes": "(max-width: 100px) 100vw, 100px",
"src": "/static/1234/c616f/test.png",
"srcSet": "/static/1234/db86b/test.png 25w,
/static/1234/356f1/test.png 50w,
/static/1234/c616f/test.png 100w",
"src": "/static/1234/62ab9/test.png",
"srcSet": "/static/1234/bb8d1/test.png 25w,
/static/1234/2f62a/test.png 50w,
/static/1234/62ab9/test.png 100w",
"srcSetType": "image/png",
"tracedSVG": "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='100'%20height='100'%3e%3cpath%20d='M41%2024c-18%207-24%2029-11%2043%2015%2017%2044%208%2046-15%201-19-17-34-35-28'%20fill='red'%20fill-rule='evenodd'/%3e%3c/svg%3e",
}
Expand Down
59 changes: 1 addition & 58 deletions packages/gatsby-plugin-sharp/src/__tests__/process-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jest.mock(`../safe-sharp`, () => {
concurrency: jest.fn(),
}
})
const { createArgsDigest, sortKeys } = require(`../process-file`)
const { createArgsDigest } = require(`../process-file`)

describe(`createArgsDigest`, () => {
const defaultArgsBaseline = {
Expand Down Expand Up @@ -64,61 +64,4 @@ describe(`createArgsDigest`, () => {
testHashDifferent(`fit change`, { fit: `CONTAIN` })
testHashDifferent(`background change`, { background: `#fff0` })
})

describe(`doesn't change hash if not used options are different`, () => {
const testHashEqual = (label, change, extraBaselineOptions = {}) => {
it(label, () => {
const argsBaseline = {
...defaultArgsBaseline,
...extraBaselineOptions,
}
const baselineHash = createArgsDigest(argsBaseline)
const outputHash = createArgsDigest({
...defaultArgsBaseline,
...change,
})
expect(baselineHash).toBe(outputHash)
})
}

testHashEqual(`unrelated argument`, { foo: `bar` })

testHashEqual(`png option change when using jpg`, {
pngCompressionLevel: defaultArgsBaseline.pngCompressionLevel + 1,
})
testHashEqual(
`jpg option change when using png`,
{
toFormat: `png`,
jpegProgressive: !defaultArgsBaseline.jpegProgressive,
},
{
toFormat: `png`,
}
)
describe(`not used arguments`, () => {
testHashEqual(`maxWidth`, { maxWidth: 500 })
testHashEqual(`base64`, { base64: true })
})

describe(`argument sorting`, () => {
it(`sorts nested arguments`, () => {
const args = {
duotone: {
shadow: `#10c5f8`,
highlight: `#32CD32`,
},
cropFocus: 17,
}
const actual = sortKeys(args)
expect(actual).toEqual({
cropFocus: 17,
duotone: {
highlight: `#32CD32`,
shadow: `#10c5f8`,
},
})
})
})
})
})
Loading

0 comments on commit 7a2a163

Please sign in to comment.