From cd304b3f8859287135e099d8001014c6b23d4c8e Mon Sep 17 00:00:00 2001 From: Dhravya Date: Mon, 24 Jun 2024 06:52:53 -0500 Subject: [PATCH] reduced db calls here, we don't need that complex logic, can just do this lol --- apps/web/app/(canvas)/canvas/[id]/page.tsx | 4 ++ apps/web/app/(canvas)/canvas/page.tsx | 11 ++-- apps/web/app/actions/fetchers.ts | 61 ++-------------------- 3 files changed, 13 insertions(+), 63 deletions(-) diff --git a/apps/web/app/(canvas)/canvas/[id]/page.tsx b/apps/web/app/(canvas)/canvas/[id]/page.tsx index e58ab35e..6efb6cf4 100644 --- a/apps/web/app/(canvas)/canvas/[id]/page.tsx +++ b/apps/web/app/(canvas)/canvas/[id]/page.tsx @@ -9,11 +9,15 @@ import { AutocompleteIcon, blockIcon } from "@repo/ui/icons"; import Image from "next/image"; import { Switch } from "@repo/ui/shadcn/switch"; import { Label } from "@repo/ui/shadcn/label"; +import { useRouter } from "next/router"; function page() { const [fullScreen, setFullScreen] = useState(false); const [visible, setVisible] = useState(true); + const router = useRouter(); + router.push("/home"); + return (
page
- ) + const router = useRouter(); + router.push("/home"); + return
page
; } -export default page \ No newline at end of file +export default page; diff --git a/apps/web/app/actions/fetchers.ts b/apps/web/app/actions/fetchers.ts index 708b82b2..0746096c 100644 --- a/apps/web/app/actions/fetchers.ts +++ b/apps/web/app/actions/fetchers.ts @@ -85,68 +85,13 @@ export const getAllUserMemoriesAndSpaces = async (): ServerActionReturnType<{ where: eq(users, data.user.id), }); - const spacesWithoutUser = spaces.map((space) => { - return { ...space, user: undefined }; + const memories = await db.query.storedContent.findMany({ + where: eq(users, data.user.id), }); - // const contentCountBySpace = await db - // .select({ - // spaceId: contentToSpace.spaceId, - // count: sql`count(*)`.mapWith(Number), - // }) - // .from(contentToSpace) - // .where( - // inArray( - // contentToSpace.spaceId, - // spacesWithoutUser.map((space) => space.id), - // ), - // ) - // .groupBy(contentToSpace.spaceId) - // .execute(); - - // console.log(contentCountBySpace); - - // get a count with space mappings like spaceID: count (number of memories in that space) - - const len = spacesWithoutUser.map((space) => space.id).length; - - if (len > 0) { - const contentCountBySpace = await db - .select({ - spaceId: contentToSpace.spaceId, - count: sql`count(*)`.mapWith(Number), - }) - .from(contentToSpace) - .where( - inArray( - contentToSpace.spaceId, - spacesWithoutUser.map((space) => space.id), - ), - ) - .groupBy(contentToSpace.spaceId) - .execute(); - - console.log(contentCountBySpace); - } - - const contentNotInAnySpace = await db - .select() - .from(storedContent) - .where( - not( - eq( - storedContent.id, - db - .select({ contentId: contentToSpace.contentId }) - .from(contentToSpace), - ), - ), - ) - .execute(); - return { success: true, - data: { spaces: spacesWithoutUser, memories: contentNotInAnySpace }, + data: { spaces: spaces, memories: memories }, }; };