fix: address react-doctor violations

This commit is contained in:
jake committed 2026-09-26 12:54:00 -04:00
1 parent 82eedf02bb
commit 2403842f39
7 files changed
+186 -228

No files matched your search

+1 -28
View File
@@ -1,6 +1,6 @@
"use server";
import { desc, eq, inArray, sql } from "drizzle-orm";
import { desc, eq, sql } from "drizzle-orm";
import { revalidatePath } from "next/cache";
import { headers } from "next/headers";
@@ -58,33 +58,6 @@ export const getCommentCount = async (slug: string): Promise<number> => {
}
};
/**
* Retrieves the numbers of comments for an array of slugs
*/
export const getCommentCountsForSlugs = async (
slugs: string[],
): Promise<Record<string, number>> => {
try {
const rows = await db
.select({
pageSlug: schema.comment.pageSlug,
count: sql<number>`cast(count(${schema.comment.id}) as int)`,
})
.from(schema.comment)
.where(inArray(schema.comment.pageSlug, slugs))
.groupBy(schema.comment.pageSlug);
const map: Record<string, number> = Object.fromEntries(slugs.map((s) => [s, 0]));
for (const row of rows) {
map[row.pageSlug] = row.count ?? 0;
}
return map;
} catch (error) {
console.error("[server/comments] error fetching comment counts:", error);
return Object.fromEntries(slugs.map((s) => [s, 0]));
}
};
/**
* Retrieves the numbers of comments for ALL slugs
*/
+1 -18
View File
@@ -1,6 +1,6 @@
"use server";
import { eq, inArray, sql } from "drizzle-orm";
import { eq, sql } from "drizzle-orm";
import { revalidateTag } from "next/cache";
import { db } from "@/lib/db";
@@ -19,23 +19,6 @@ export const getViewCount = async (slug: string): Promise<number> => {
}
};
/**
* Retrieves the numbers of views for an array of slugs, returning 0 for any that don't exist
*/
export const getViewCountsForSlugs = async (slugs: string[]): Promise<Record<string, number>> => {
try {
const pages = await db.select().from(page).where(inArray(page.slug, slugs));
const viewMap: Record<string, number> = Object.fromEntries(slugs.map((s) => [s, 0]));
for (const p of pages) {
viewMap[p.slug] = p.views;
}
return viewMap;
} catch (error) {
console.error("[server/views] fatal error:", error);
return Object.fromEntries(slugs.map((s) => [s, 0]));
}
};
/**
* Retrieves the numbers of views for ALL slugs
*/