Skip to content

fix(search): truncate excerpt in sanitizeHtml to prevent slow search#3199

Open
jancborchardt wants to merge 3 commits into
mainfrom
worktree-fix+search-slow-excerpt-truncation
Open

fix(search): truncate excerpt in sanitizeHtml to prevent slow search#3199
jancborchardt wants to merge 3 commits into
mainfrom
worktree-fix+search-slow-excerpt-truncation

Conversation

@jancborchardt
Copy link
Copy Markdown
Member

@jancborchardt jancborchardt commented May 22, 2026

Summary

  • sanitizeHtml() added in Improve note preview #3155 returned the full note content untruncated, while the markdown path always calls truncateString(result, 200)
  • Any note whose content matches HTML_PATTERN (which includes informal tags like <todo>, generics like List<String>, or Markdown email syntax like <user@host>) would have its full 35–41 kB stored as the excerpt in the database
  • On every search keystroke the adapter called textView.setText() and highlightText() with those large strings on the main thread for every visible item, blocking the UI for several seconds (reported in Search very slow since latest release #3180)
  • Fix: strip remaining HTML tags and truncate to 200 chars in sanitizeHtml(), consistent with the markdown path — SQL LIKE search still operates on the full note content

Test plan

  • Open a folder containing large (>10 kB) notes that have any angle-bracket content (code snippets, <placeholder> syntax, email addresses, etc.)
  • Type in the search bar — text should appear instantly and list should filter without delay
  • Verify note excerpts show plain text (no raw HTML tags)
  • Run unit tests: ./gradlew :app:testFdroidDebugUnitTest --tests "it.niedermann.owncloud.notes.shared.util.NoteUtilTest"

Fixes #3180

🤖 Generated with Claude Code

@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 22, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@github-actions

This comment was marked as outdated.

generateNoteExcerpt() always truncated to 200 chars via truncateString()
on the markdown path, but the sanitizeHtml() path added in #3155 returned
the full content untruncated. Any note whose content matches the broad
HTML_PATTERN (which includes informal tags like <todo>, <action>, generics
like List<String>, or Markdown email syntax) would have its full 35-41 kB
stored as the excerpt. On every search keystroke, the adapter called
textView.setText() and highlightText() with those large strings on the
main thread for every visible item, blocking the UI for several seconds.

Fix: strip remaining HTML tags and truncate to 200 chars in sanitizeHtml(),
consistent with the markdown path. Search still operates on the full note
content via SQL LIKE.

Fixes: #3180

AI-assisted: Claude Code (Sonnet 4.6)
Signed-off-by: Jan C. Borchardt <925062+jancborchardt@users.noreply.github.com>
Fixes Codacy complexity warnings about duplicate string literals.

AI-assisted: Claude Code (Sonnet 4.6)
Signed-off-by: Jan C. Borchardt <925062+jancborchardt@users.noreply.github.com>
Fixes Codacy documentation warning.

AI-assisted: Claude Code (Sonnet 4.6)
Signed-off-by: Jan C. Borchardt <925062+jancborchardt@users.noreply.github.com>
@jancborchardt jancborchardt force-pushed the worktree-fix+search-slow-excerpt-truncation branch from 6501f55 to 95c079c Compare May 22, 2026 23:01
@jancborchardt jancborchardt self-assigned this May 22, 2026
@jancborchardt jancborchardt moved this to 🏗️ At engineering in 🖍 Design team May 22, 2026
@github-actions
Copy link
Copy Markdown
Contributor

APK file: https://github.com/nextcloud/notes-android/actions/runs/26316063945/artifacts/7171801123
To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.
qrcode (please click on link to get QR code displayed)

@jancborchardt jancborchardt added the papercut Annoying recurring UX issue with possibly simple fix. label May 22, 2026
Copy link
Copy Markdown
Member Author

@jancborchardt jancborchardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and can confirm this fixes the search performance issue introduced by #3155 @alperozturk96

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review bug papercut Annoying recurring UX issue with possibly simple fix.

Projects

Status: 🏗️ At engineering

Development

Successfully merging this pull request may close these issues.

Search very slow since latest release

1 participant