mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-10-27 13:16:30 -04:00
fix: address react-doctor violations
This commit is contained in:
7 files changed
+186
-228
No files matched your search
+1
-28
@@ -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
@@ -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
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user