WeKnora/internal/utils
adawang 3b317f7eef perf(utils): compile SQL-validation regexps once instead of per call
checkSQLInjectionRisks and InjectAndConditions compiled their regexps
with regexp.MustCompile on every invocation. Both run on the datasource
SQL path — InjectAndConditions is called once per security filter
(tenant, soft-delete, hidden-KB, search-scope), so a single secured query
recompiled ~20 patterns. InjectAndConditions also compiled the identical
tail-clause pattern twice.

Hoist them to package-level vars (compiled once at init). Behavior is
unchanged — same patterns, covered by the existing TestValidateSQL_*
and TestInjectAndConditions tests.

Benchmarks (apple M, -benchmem):
  InjectAndConditions    4347 ns, 72 allocs -> 1023 ns, 7 allocs
  checkSQLInjectionRisks 36074 ns, 560 allocs -> 12984 ns, 12 allocs

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-17 14:17:17 +08:00
..
crypto.go feat(crypto): AES-GCM at-rest for MCP and DataSource credentials with graceful key-rotation handling 2026-05-17 15:27:52 +08:00
crypto_test.go fix(crypto): fail loudly when encrypted DB fields cannot be decrypted 2026-04-30 15:17:56 +08:00
debug.go feat: 使用增强的任务ID生成器替换UUID 2026-01-14 17:09:19 +08:00
extraheaders.go fix(embedding): support native Gemini embeddings 2026-06-02 21:37:58 +08:00
extraheaders_test.go fix(embedding): support native Gemini embeddings 2026-06-02 21:37:58 +08:00
filesize.go feat(system): consolidate system admin and settings into one Settings panel 2026-05-26 21:13:56 +08:00
fileutil.go fix(storage): auto-detect content-type to resolve image rendering issues 2026-04-20 21:59:54 +08:00
httputil.go feat: enhance document loading and state management in doc-content component 2026-03-02 21:21:49 +08:00
inject.go perf(utils): compile SQL-validation regexps once instead of per call 2026-06-17 14:17:17 +08:00
inject_test.go perf(utils): compile SQL-validation regexps once instead of per call 2026-06-17 14:17:17 +08:00
json.go feat: Add DataSchema tool for retrieving schema information from CSV and Excel files 2025-12-29 20:03:51 +08:00
log_sanitize.go feat: implement image upload and multimodal support 2026-03-12 10:32:26 +08:00
presign.go feat: implement tenant validation for file access and enhance related tests 2026-05-29 13:47:32 +08:00
presign_test.go feat: implement tenant validation for file access and enhance related tests 2026-05-29 13:47:32 +08:00
security.go feat(system): consolidate system admin and settings into one Settings panel 2026-05-26 21:13:56 +08:00
security_test.go feat(retriever): add OpenSearch driver skeleton + interface stubs (PR 2a of 3) 2026-05-26 20:54:58 +08:00
taskid.go feat: 使用增强的任务ID生成器替换UUID 2026-01-14 17:09:19 +08:00