Only call search API when pause in typing search query on web, desktop apps

Wait for 300ms since stop typing before calling search API.

This smooths out UI jitter when rendering search results, especially
now that we're reranking for every search query on GPU enabled devices

Emacs already has 300ms debounce time. More convoluted to add
debounce time to Obsidian search modal, so not updating that yet
This commit is contained in:
Debanjum Singh Solanky 2024-03-09 17:53:04 +05:30
parent 1105d8814f
commit 44c8d09342
2 changed files with 20 additions and 18 deletions

View file

@ -192,16 +192,17 @@
}); });
} }
let debounceTimeout;
function incrementalSearch(event) { function incrementalSearch(event) {
// Run incremental search only after waitTime passed since the last key press
let waitTime = 300;
clearTimeout(debounceTimeout);
debounceTimeout = setTimeout(() => {
type = 'all'; type = 'all';
// Search with reranking on 'Enter' // Search with reranking on 'Enter'
if (event.key === 'Enter') { let should_rerank = event.key === 'Enter';
search(rerank=true); search(rerank=should_rerank);
} }, waitTime);
// Limit incremental search to text types
else if (type !== "image") {
search(rerank=false);
}
} }
async function populate_type_dropdown() { async function populate_type_dropdown() {

View file

@ -193,16 +193,17 @@
}); });
} }
let debounceTimeout;
function incrementalSearch(event) { function incrementalSearch(event) {
// Run incremental search only after waitTime passed since the last key press
let waitTime = 300;
clearTimeout(debounceTimeout);
debounceTimeout = setTimeout(() => {
type = document.getElementById("type").value; type = document.getElementById("type").value;
// Search with reranking on 'Enter' // Search with reranking on 'Enter'
if (event.key === 'Enter') { let should_rerank = event.key === 'Enter';
search(rerank=true); search(rerank=should_rerank);
} }, waitTime);
// Limit incremental search to text types
else if (type !== "image") {
search(rerank=false);
}
} }
function populate_type_dropdown() { function populate_type_dropdown() {