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(remix-architect,remix-netlify): improve performance of isBinaryType #4761

Merged
merged 4 commits into from
Dec 15, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/late-bottles-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"remix": patch
"@remix-run/architect": patch
"@remix-run/netlify": patch
---

improve performance of `isBinaryType` in the netlify and architect adapters

previous implementation from arc itself has a complexity of O(N*includesComplexity), where as now it is O(includesComplexity).
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
- guatedude2
- guerra08
- gunners6518
- gyx1000
- hadizz
- hardingmatt
- helderburato
Expand Down
11 changes: 11 additions & 0 deletions packages/remix-architect/__tests__/binaryTypes-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { isBinaryType } from "../binaryTypes";

describe("architect isBinaryType", () => {
it("should detect binary contentType correctly", () => {
expect(isBinaryType(undefined)).toBe(false);
expect(isBinaryType(null)).toBe(false);
expect(isBinaryType("text/html; charset=utf-8")).toBe(false);
expect(isBinaryType("application/octet-stream")).toBe(true);
expect(isBinaryType("application/octet-stream; charset=test")).toBe(true);
});
});
3 changes: 2 additions & 1 deletion packages/remix-architect/binaryTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ const binaryTypes = [

export function isBinaryType(contentType: string | null | undefined) {
if (!contentType) return false;
return binaryTypes.some((t) => contentType.includes(t));
let [test] = contentType.split(";");
return binaryTypes.includes(test);
}
11 changes: 11 additions & 0 deletions packages/remix-netlify/__tests__/binaryTypes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { isBinaryType } from "../binaryTypes";

describe("architect isBinaryType", () => {
it("should detect binary contentType correctly", () => {
expect(isBinaryType(undefined)).toBe(false);
expect(isBinaryType(null)).toBe(false);
expect(isBinaryType("text/html; charset=utf-8")).toBe(false);
expect(isBinaryType("application/octet-stream")).toBe(true);
expect(isBinaryType("application/octet-stream; charset=test")).toBe(true);
});
});
3 changes: 2 additions & 1 deletion packages/remix-netlify/binaryTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ const binaryTypes = [

export function isBinaryType(contentType: string | null | undefined) {
if (!contentType) return false;
return binaryTypes.some((t) => contentType.includes(t));
let [test] = contentType.split(";");
return binaryTypes.includes(test);
}