diff --git a/web/app/routes/home.tsx b/web/app/routes/home.tsx index 55f902b..5406e7a 100644 --- a/web/app/routes/home.tsx +++ b/web/app/routes/home.tsx @@ -26,11 +26,10 @@ interface DomainStatRow { domain: string; collection_count: string; total_count: string; - avg_count: string; last_seen: string; first_seen: string; total_domains: string; - max_avg_count: string; + max_total_count: string; } interface CollectionRow { @@ -64,7 +63,7 @@ export async function loader({ request }: LoaderFunctionArgs) { const offset = (page - 1) * PAGE_SIZE; // sort and dir are both validated to a fixed set — safe to interpolate const sortCol = - sort === "count" ? "avg_count" : + sort === "count" ? "total_count" : sort === "first_seen" ? "first_seen" : "last_seen"; const orderSql = `${sortCol} ${dir === "asc" ? "ASC" : "DESC"}`; @@ -79,7 +78,6 @@ export async function loader({ request }: LoaderFunctionArgs) { split_part(name, '.', 1) || '.' || split_part(name, '.', 2) AS domain, COUNT(*)::bigint AS collection_count, SUM(count)::bigint AS total_count, - (SUM(count) / NULLIF(COUNT(*), 0))::bigint AS avg_count, MAX(last_seen) AS last_seen, MIN(first_seen) AS first_seen FROM collection_stats @@ -90,11 +88,10 @@ export async function loader({ request }: LoaderFunctionArgs) { domain, collection_count::text, total_count::text, - avg_count::text, last_seen, first_seen, - COUNT(*) OVER ()::text AS total_domains, - MAX(avg_count) OVER ()::text AS max_avg_count + COUNT(*) OVER ()::text AS total_domains, + MAX(total_count) OVER ()::text AS max_total_count FROM domain_stats ORDER BY ${orderSql} LIMIT $${paramOffset} OFFSET $${paramOffset + 1} @@ -123,7 +120,7 @@ export async function loader({ request }: LoaderFunctionArgs) { const domains = domainResult.rows; const totalDomains = parseInt(domains[0]?.total_domains ?? "0", 10); - const maxAvgCount = parseInt(domains[0]?.max_avg_count ?? "1", 10); + const maxTotalCount = parseInt(domains[0]?.max_total_count ?? "1", 10); const totalPages = Math.max(1, Math.ceil(totalDomains / PAGE_SIZE)); // Fetch all collections for the visible domain cards in one query @@ -156,7 +153,7 @@ export async function loader({ request }: LoaderFunctionArgs) { })), total: totalDomains, totalPages, - maxAvgCount, + maxTotalCount, page: Math.min(page, totalPages), q, sort, @@ -209,7 +206,7 @@ function buildLink( } export default function Home() { - const { domains, total, totalPages, page, q, sort, dir, hideBsky, view, maxAvgCount, totalCollections, totalRecords } = + const { domains, total, totalPages, page, q, sort, dir, hideBsky, view, maxTotalCount, totalCollections, totalRecords } = useLoaderData(); const navigation = useNavigation(); const isLoading = navigation.state === "loading"; @@ -345,7 +342,7 @@ export default function Home() {
Sort: - +
{domains.map((domain) => { - const avgCount = parseInt(domain.avg_count, 10); + const totalCount = parseInt(domain.total_count, 10); const collectionCount = parseInt(domain.collection_count, 10); - const barWidth = Math.max(2, Math.round((avgCount / maxAvgCount) * 100)); + const barWidth = Math.max(2, Math.round((totalCount / maxTotalCount) * 100)); const domainUrl = domainToUrl(domain.domain); return ( @@ -413,13 +410,17 @@ export default function Home() { {domain.domain} -
- - {formatCount(avgCount)} - {" "} - avg/type - · - {collectionCount} {collectionCount === 1 ? "type" : "types"} +
+
+ + {formatCount(totalCount)} + {" "} + records + · + {collectionCount} {collectionCount === 1 ? "collection" : "collections"} +
+
first {formatDate(domain.first_seen)}
+
last {formatDate(domain.last_seen)}
{domains.map((domain) => { - const avgCount = parseInt(domain.avg_count, 10); + const totalCount = parseInt(domain.total_count, 10); const collectionCount = parseInt(domain.collection_count, 10); - const barWidth = Math.max(2, Math.round((avgCount / maxAvgCount) * 100)); + const barWidth = Math.max(2, Math.round((totalCount / maxTotalCount) * 100)); const domainUrl = domainToUrl(domain.domain); return ( @@ -492,15 +493,17 @@ export default function Home() { {domain.domain} -
- - {formatCount(avgCount)} - {" "} - avg/type - · - {collectionCount} {collectionCount === 1 ? "type" : "types"} - · - last seen {formatDate(domain.last_seen)} +
+
+ + {formatCount(totalCount)} + {" "} + records + · + {collectionCount} {collectionCount === 1 ? "collection" : "collections"} +
+
first {formatDate(domain.first_seen)}
+
last {formatDate(domain.last_seen)}
{/* Bar */}