Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: memoize isMediaUrl #688

Merged
merged 2 commits into from Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -158,8 +158,8 @@
"build": "gulp build",
"clean": "pnpm --recursive --parallel exec -- rm -rf node_modules",
"contributors": "npm run contributors:add && npm run contributors:commit",
"contributors:add": "pnpm --recursive --parallel exec -- finepack --sort-ignore-object-at ava",
"contributors:commit": "(git-authors-cli && finepack --sort-ignore-object-at ava && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
"contributors:add": "pnpm --recursive --parallel exec -- finepack",
"contributors:commit": "(git-authors-cli && finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
"coverage": "c8 report --reporter=text-lcov > coverage/lcov.info",
"dev": "concurrently \"gulp\" \"npm run dev:server\"",
"dev:server": "browser-sync start --server --files \"index.html, README.md, static/**/*.(css|js)\"",
Expand Down
6 changes: 4 additions & 2 deletions packages/metascraper-helpers/index.js
Expand Up @@ -209,8 +209,10 @@ const isMediaTypeUrl = (url, type, { ext, ...opts } = {}) =>
const isMediaTypeExtension = (url, type, ext) =>
eq(type, get(EXTENSIONS, ext || extension(url)))

const isMediaUrl = (url, opts) =>
isImageUrl(url, opts) || isVideoUrl(url, opts) || isAudioUrl(url, opts)
const isMediaUrl = memoizeOne(
(url, opts) =>
isImageUrl(url, opts) || isVideoUrl(url, opts) || isAudioUrl(url, opts)
)

const isVideoUrl = (url, opts) => isMediaTypeUrl(url, VIDEO, opts)

Expand Down