Use server-side ?search= API instead of client-side filtering
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -126,18 +126,16 @@ function RelationManager({ recordId, rel }) {
|
|||||||
if (!search.trim()) { setSearchResults([]); return; }
|
if (!search.trim()) { setSearchResults([]); return; }
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
setSearching(true);
|
setSearching(true);
|
||||||
apiFetch(`${rel.searchEndpoint}?limit=500&offset=0`)
|
const q = encodeURIComponent(search.trim());
|
||||||
|
apiFetch(`${rel.searchEndpoint}?search=${q}&limit=20&offset=0`)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
const arr = Array.isArray(data) ? data : [];
|
const arr = Array.isArray(data) ? data : [];
|
||||||
const q = search.toLowerCase();
|
|
||||||
const linked = new Set((items || []).map(i => i.id));
|
const linked = new Set((items || []).map(i => i.id));
|
||||||
setSearchResults(
|
setSearchResults(arr.filter(r => !linked.has(r.id)));
|
||||||
arr.filter(r => rel.searchLabel(r).toLowerCase().includes(q) && !linked.has(r.id))
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.catch(() => setSearchResults([]))
|
.catch(() => setSearchResults([]))
|
||||||
.finally(() => setSearching(false));
|
.finally(() => setSearching(false));
|
||||||
}, 250);
|
}, 300);
|
||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}, [search, showSearch, items, rel]);
|
}, [search, showSearch, items, rel]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user