-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Enhance search by filtering by URL, hostname and dns resolve server #5438
base: master
Are you sure you want to change the base?
Conversation
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.
At its core this is reasonable change.
I am a bit sussed out by this code in terms of performance as I implemented something similar in another project and the performance was pretty bad.
I think we should switch to Regex comparisons instead as they are faster than the call to .toLowerCase()
as far as I remember and can handle caseness.
What do you think?
Except with less than 20 monitors, regex seems faster.
Hi @CommanderStorm! After some tests, it appears regex is more efficient when you have ~100monitors. Before, lower-case can be better. But because UK is designed to handle a lot of monitors, regex has been used instead. Thanks for the suggestion!! |
I was thinking more along the lines of something like this: // filter by search text using regex
// matches monitor name, tag name, or tag value
let searchTextMatch = true;
if (this.searchText !== "") {
try {
const regex = new RegExp(this.searchText, "i"); // "i" for case-insensitive matching
searchTextMatch =
regex.test(monitor.name) ||
(monitor.url && regex.test(monitor.url)) ||
(monitor.hostname && regex.test(monitor.hostname)) ||
(monitor.dns_resolve_server && regex.test(monitor.dns_resolve_server)) ||
monitor.tags.some(tag => regex.test(tag.name) || (tag.value && regex.test(tag.value)));
} catch (e) {
console.error("Invalid regex pattern:", e);
searchTextMatch = false;
}
} |
Relevant indeed, I forgot to take into account the null/undefined values. Will do the changes, thanks @homelab-alpha |
Or better: suggest the change via the review feature so you can appear in the contributors. |
@Ionys320 , You came up with the fix, we can share the credit. 😊 |
…lso optimize a bit search tags by replacing `.find` with `.some`. Thanks @homelab-alpha
So, the input is now regex friendly, that's fun. I wonder if it can broke something, I tried do search a fiew fields and it went fine. |
I'd consider regexes working somewhat like a feature. I am fine with both |
Approved then! |
This can be reverted if the search should be regex friendly, but for the moment, it's not the case. Thanks @homelab-alpha!
Okay so: the searchbar is now escaping regex expression (#5466 (comment)). This PR creates the issue #5466. This issue occures because the PR extends the used fiels, but the PR is not creating the issue neither. But maybe fix #5466 before merging the PR would be a good move. |
https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md#can-i-create-a-pull-request-for-uptime-kuma
Tick the checkbox if you understand [x]:
Description
Fixes #5422 . This PR is pretty simple (just three lines enhancing existing filters), but makes so much sens to me..
Note: Even if this is not supposed to occurs, the code handle the case url would be null/undefined.
Type of change
Checklist
Screenshots