feat: auto-detect exact hostname filter for faster queries#152
Open
feat: auto-detect exact hostname filter for faster queries#152
Conversation
When the host filter input looks like a complete hostname (has a dot, valid chars, no wildcards), use exact = on request.host instead of LIKE '%...%'. This leverages the primary key ordering for faster queries. Keeps LIKE on x_forwarded_host since it stores comma-separated values. Adds a visual "exact"/"partial" indicator badge next to the filter input. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Lars Trieloff <lars@trieloff.net>
Preview deploymentPreview is live at: https://klickhaus.aemstatus.net/preview/pr-152/dashboard.html Updated for commit 60cf2a3 |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an auto-detected “exact hostname” mode for the host filter to speed up ClickHouse queries by using request.host = '…' when the filter looks like a full hostname, while keeping LIKE matching for partial patterns and x_forwarded_host.
Changes:
- Introduces
isExactHostname()and usesstate.hostFilterExactto choose between exact (=) vs partial (LIKE) host filtering. - Persists exact-mode via URL state (
domainExact=1) and addshostFilterExactto global state. - Adds a small “exact/partial” badge next to the host filter input across dashboards, plus styling.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
js/time.js |
Adds hostname heuristic and updates SQL generation to use = for exact matches. |
js/state.js |
Adds hostFilterExact to shared state. |
js/url-state.js |
Serializes/deserializes hostFilterExact via domainExact=1 and auto-detects on load. |
js/dashboard-init.js |
Updates UI to show “exact/partial” badge and sets hostFilterExact on user input. |
js/time.test.js |
Adds tests for isExactHostname() and exact-mode SQL generation. |
js/url-state.test.js |
Adds tests for exact detection on URL load and domainExact round-trip. |
dashboard.html / delivery.html / lambda.html |
Adds the badge element next to the host filter input. |
css/layout.css |
Styles the badge and hides it on mobile. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+96
to
+109
| function updateHostFilterIndicator(value) { | ||
| const badge = elements.hostFilterMode; | ||
| if (!badge) return; | ||
| if (!value) { | ||
| badge.textContent = ''; | ||
| badge.className = 'filter-mode-badge'; | ||
| return; | ||
| } | ||
| const exact = isExactHostname(value); | ||
| badge.textContent = exact ? 'exact' : 'partial'; | ||
| badge.className = exact | ||
| ? 'filter-mode-badge filter-mode-exact' | ||
| : 'filter-mode-badge filter-mode-partial'; | ||
| } |
Comment on lines
403
to
409
| elements.hostFilterInput.addEventListener('input', (e) => { | ||
| updateHostFilterIndicator(e.target.value); | ||
| clearTimeout(filterTimeout); | ||
| filterTimeout = setTimeout(() => { | ||
| state.hostFilter = e.target.value; | ||
| state.hostFilterExact = isExactHostname(state.hostFilter); | ||
| saveStateToURL(); |
Comment on lines
+124
to
+125
| state.hostFilterExact = params.get('domainExact') === '1' | ||
| || isExactHostname(state.hostFilter); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Auto-detect whether the hostname filter input is a complete hostname (e.g.
www.adobe.com) or a partial pattern (e.g.adobe), and use exact=match onrequest.hostinstead ofLIKE '%…%'when appropriate.Changes:
isExactHostname()heuristic injs/time.js— detects valid hostnames (has dot, valid chars, no wildcards)getHostFilter()to use=onrequest.hostfor exact matches (primary key benefit), keepingLIKEonx_forwarded_host(comma-separated values)hostFilterExactto state and URL serialization (domainExact=1param)Testing Done
npm run lint— passes (0 errors)npm test— 785/785 tests pass, 95.82% coverageisExactHostname()covering edge cases (dots, wildcards, trailing dots, etc.)getHostFilter()SQL generationdomainExactURL param round-tripChecklist
npm test)npm run lint)