Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-18 04:34:37 +00:00
co-authored by renee-png
parent a6bae35705
commit 99c79741d8
+38 -3
View File
@@ -47,10 +47,45 @@ function ContactsIndex() {
const load = async () => {
setLoading(true);
// Paginate to bypass Supabase's 1000-row default limit
const fetchAllContacts = async () => {
const pageSize = 1000;
let from = 0;
const all: any[] = [];
while (true) {
const { data, error } = await supabase
.from("contacts")
.select("*")
.order("name")
.range(from, from + pageSize - 1);
if (error) return { data: all, error };
if (!data || data.length === 0) break;
all.push(...data);
if (data.length < pageSize) break;
from += pageSize;
}
return { data: all, error: null as any };
};
const fetchAllLinks = async (table: "case_contacts" | "client_contacts") => {
const pageSize = 1000;
let from = 0;
const all: any[] = [];
while (true) {
const { data, error } = await supabase
.from(table)
.select("contact_id")
.range(from, from + pageSize - 1);
if (error || !data || data.length === 0) break;
all.push(...data);
if (data.length < pageSize) break;
from += pageSize;
}
return { data: all };
};
const [{ data, error }, { data: cc }, { data: clc }] = await Promise.all([
supabase.from("contacts").select("*").order("name"),
supabase.from("case_contacts").select("contact_id"),
supabase.from("client_contacts").select("contact_id"),
fetchAllContacts(),
fetchAllLinks("case_contacts"),
fetchAllLinks("client_contacts"),
]);
if (error) toast.error(error.message);
const caseCounts = new Map<string, number>();