mirror of
https://github.com/Hackdex-App/hackdex-website.git
synced 2026-08-22 00:24:34 -05:00
Fix trending rankings for hacks with many patches (#73)
This commit is contained in:
@@ -190,13 +190,33 @@ export async function getDiscoverData(sort: DiscoverSortOption): Promise<Discove
|
||||
// Calculate trending scores if needed
|
||||
let trendingScores: Map<string, number> | null = null;
|
||||
if (sort === "trending") {
|
||||
// Get all patches for all hacks, grouped by slug
|
||||
// Get all patches for all hacks, grouped by slug.
|
||||
// Paginate rows per slug chunk to avoid the PostgREST 1000-row cap.
|
||||
const { data: allPatches, error: allPatchesError } = await fetchInChunks(slugs, CHUNK_SIZE, async (chunk) => {
|
||||
const { data, error } = await supabase
|
||||
.from("patches")
|
||||
.select("id,parent_hack")
|
||||
.in("parent_hack", chunk);
|
||||
return { data, error };
|
||||
const rows: { id: number; parent_hack: string | null }[] = [];
|
||||
let offset = 0;
|
||||
let hasMore = true;
|
||||
|
||||
while (hasMore) {
|
||||
const { data, error } = await supabase
|
||||
.from("patches")
|
||||
.select("id,parent_hack")
|
||||
.in("parent_hack", chunk)
|
||||
.order("id", { ascending: true })
|
||||
.range(offset, offset + ROW_BATCH_SIZE - 1);
|
||||
|
||||
if (error) return { data: null, error };
|
||||
|
||||
if (!data || data.length === 0) {
|
||||
hasMore = false;
|
||||
} else {
|
||||
rows.push(...data);
|
||||
hasMore = data.length === ROW_BATCH_SIZE;
|
||||
if (hasMore) offset += ROW_BATCH_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
return { data: rows, error: null };
|
||||
});
|
||||
if (allPatchesError) throw allPatchesError;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user