Skip to content

Commit 4e033a7

Browse files
authored
Merge pull request #7105 from Shopify/perf/asset-checksum-set-lookup
optimize asset checksum filtering with Set lookup
2 parents 644636b + bfca4c1 commit 4e033a7

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

packages/theme/src/cli/utilities/asset-checksum.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,27 +85,23 @@ function md5(content: string | Buffer) {
8585
* as these are not needed for theme comparison.
8686
*/
8787
export function rejectGeneratedStaticAssets(themeChecksums: Checksum[]) {
88+
const liquidAssetKeys = new Set(
89+
themeChecksums
90+
.filter(({key}) => key.startsWith('assets/') && key.endsWith('.liquid'))
91+
.map(({key}) => key),
92+
)
93+
8894
return themeChecksums.filter(({key}) => {
8995
const isStaticAsset = key.startsWith('assets/')
9096

9197
if (isStaticAsset) {
92-
return !hasLiquidSource(themeChecksums, key)
98+
return !liquidAssetKeys.has(`${key}.liquid`)
9399
}
94100

95101
return true
96102
})
97103
}
98104

99-
/**
100-
* Checks if a given key has a corresponding liquid source in the provided checksums.
101-
* @param checksums - The array of checksums to search through.
102-
* @param key - The key to check for a liquid source.
103-
* @returns True if a liquid source exists for the given key, false otherwise.
104-
*/
105-
function hasLiquidSource(checksums: Checksum[], key: string) {
106-
return checksums.some((checksum) => checksum.key === `${key}.liquid`)
107-
}
108-
109105
function isSettingsData(path: string) {
110106
return path.endsWith('/settings_data.json')
111107
}

0 commit comments

Comments
 (0)