feat(quick_search): limit the size of the Notes to search through, to 2MB

This commit is contained in:
perf3ct 2025-08-03 19:31:37 +00:00
parent c603783a44
commit 057040af06
No known key found for this signature in database
GPG Key ID: 569C4EEC436F5232

View File

@ -22,6 +22,9 @@ import {
const ALLOWED_OPERATORS = new Set(["=", "!=", "*=*", "*=", "=*", "%=", "~=", "~*"]); const ALLOWED_OPERATORS = new Set(["=", "!=", "*=*", "*=", "=*", "%=", "~=", "~*"]);
// Maximum content size for search processing (2MB)
const MAX_SEARCH_CONTENT_SIZE = 2 * 1024 * 1024;
const cachedRegexes: Record<string, RegExp> = {}; const cachedRegexes: Record<string, RegExp> = {};
function getRegex(str: string): RegExp { function getRegex(str: string): RegExp {
@ -77,7 +80,9 @@ class NoteContentFulltextExp extends Expression {
for (const row of sql.iterateRows<SearchRow>(` for (const row of sql.iterateRows<SearchRow>(`
SELECT noteId, type, mime, content, isProtected SELECT noteId, type, mime, content, isProtected
FROM notes JOIN blobs USING (blobId) FROM notes JOIN blobs USING (blobId)
WHERE type IN ('text', 'code', 'mermaid', 'canvas', 'mindMap') AND isDeleted = 0`)) { WHERE type IN ('text', 'code', 'mermaid', 'canvas', 'mindMap')
AND isDeleted = 0
AND LENGTH(content) < ${MAX_SEARCH_CONTENT_SIZE}`)) {
this.findInText(row, inputNoteSet, resultNoteSet); this.findInText(row, inputNoteSet, resultNoteSet);
} }
@ -155,11 +160,9 @@ class NoteContentFulltextExp extends Expression {
content = normalize(content.toString()); content = normalize(content.toString());
if (type === "text" && mime === "text/html") { if (type === "text" && mime === "text/html") {
if (!this.raw && content.length < 10 * 1024 * 1024) { if (!this.raw) {
// striptags is slow for very large notes - allow up to 10MB HTML processing // Content size already filtered at DB level, safe to process
content = this.stripTags(content); content = this.stripTags(content);
} else if (!this.raw) {
console.info(`Skipping HTML tag stripping for very large note: ${content.length} bytes - will search raw HTML`);
} }
content = content.replace(/&nbsp;/g, " "); content = content.replace(/&nbsp;/g, " ");