-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Bolt: [성능 개선] PDF 바이트 검증 최적화 #1267
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -91,8 +91,19 @@ export async function readScorePdf(projectId: string, scoreId: string): Promise< | |||||||||||||||||||||||||||||||
| if (response instanceof ArrayBuffer) { | ||||||||||||||||||||||||||||||||
| return new Uint8Array(response); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| if (Array.isArray(response) && response.every((byte) => typeof byte === "number")) { | ||||||||||||||||||||||||||||||||
| return Uint8Array.from(response as number[]); | ||||||||||||||||||||||||||||||||
| if (Array.isArray(response)) { | ||||||||||||||||||||||||||||||||
| // Performance: Avoid massive O(N) callback overhead of .every() on large byte arrays (e.g. megabyte-sized PDFs). | ||||||||||||||||||||||||||||||||
| // A traditional for loop significantly reduces main-thread blocking time during validation. | ||||||||||||||||||||||||||||||||
| let isValid = true; | ||||||||||||||||||||||||||||||||
| for (let i = 0; i < response.length; i++) { | ||||||||||||||||||||||||||||||||
| if (typeof response[i] !== "number") { | ||||||||||||||||||||||||||||||||
| isValid = false; | ||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| if (isValid) { | ||||||||||||||||||||||||||||||||
| return Uint8Array.from(response as number[]); | ||||||||||||||||||||||||||||||||
|
Comment on lines
+99
to
+105
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: git diff --unified=30 314ddeae7b775a4957594b599358c8255617eb2e 1f95f629945199fc9b3483fd8287b6f1fb96eeb9 -- apps/desktop/src/features/score/scoreStorage.ts apps/desktop/src/features/score/scoreStorage.test.ts
sed -n '78,118p' apps/desktop/src/features/score/scoreStorage.ts
sed -n '1,90p' apps/desktop/src/features/score/scoreStorage.test.ts
rg -n 'readScorePdf|score.*pdf|score_pdf|scorePdf' apps/desktop
for f in AGENTS.md apps/AGENTS.md apps/desktop/AGENTS.md apps/desktop/src/AGENTS.md apps/desktop/src/features/AGENTS.md apps/desktop/src/features/score/AGENTS.md; do if test -f "$f"; then printf '\n--- %s ---\n' "$f"; sed -n '1,220p' "$f"; fi; doneRepository: ContextualWisdomLab/bandscope Length of output: 41376 🏁 Script executed: set -eu
printf '%s\n' '--- Rust command and imports ---'
sed -n '1,80p' apps/desktop/src-tauri/src/main.rs
sed -n '780,858p' apps/desktop/src-tauri/src/main.rs
printf '%s\n' '--- Frontend bridge helper ---'
sed -n '1,130p' apps/desktop/src/features/score/scoreStorage.ts
printf '%s\n' '--- Relevant security guidance ---'
rg -n -C 4 'strict schema|schema validation|IPC|untrusted|byte|Uint8|Tauri' docs/security AGENTS.md
printf '%s\n' '--- Exact old/new function bodies ---'
git show 314ddeae7b775a4957594b599358c8255617eb2e:apps/desktop/src/features/score/scoreStorage.ts | sed -n '78,116p'
git show 1f95f629945199fc9b3483fd8287b6f1fb96eeb9:apps/desktop/src/features/score/scoreStorage.ts | sed -n '78,116p'
printf '%s\n' '--- Rust return-type references ---'
rg -n -C 3 'read_score_pdf|Vec<u8>|serialize|serde' apps/desktop/src-tauri/src apps/desktop/core/srcRepository: ContextualWisdomLab/bandscope Length of output: 41945 PDF 바이트 원소를 정수와
수정 예시 let isValid = true;
for (let i = 0; i < response.length; i++) {
- if (typeof response[i] !== "number") {
+ const value = response[i];
+ if (!Number.isInteger(value) || value < 0 || value > 255) {
isValid = false;
break;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| throw new Error(INVALID_RESPONSE_MESSAGE); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win
동기 루프가 메인 스레드 차단을 막는다고 쓰지 마세요.
이
for루프도 동기식 순회이므로 실행 중 메인 스레드를 점유합니다..every()보다 차단 시간을 줄일 수는 있지만, 차단 자체를 방지하지는 않습니다.prevent를 차단 시간 감소를 나타내는 문구로 바꾸세요.문구 수정 예시
📝 Committable suggestion
🤖 Prompt for AI Agents