mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-10-07 02:58:11 +00:00
reduced db calls here, we don't need that complex logic, can just do this lol
This commit is contained in:
parent
4c86f1eaa2
commit
cd304b3f88
3 changed files with 13 additions and 63 deletions
|
|
@ -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 (
|
||||
<div
|
||||
className={`h-screen w-full ${!fullScreen ? "px-4 py-6" : "bg-[#1F2428]"} transition-all`}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import React from 'react'
|
||||
import { useRouter } from "next/router";
|
||||
import React from "react";
|
||||
|
||||
function page() {
|
||||
return (
|
||||
<div>page</div>
|
||||
)
|
||||
const router = useRouter();
|
||||
router.push("/home");
|
||||
return <div>page</div>;
|
||||
}
|
||||
|
||||
export default page
|
||||
export default page;
|
||||
|
|
|
|||
|
|
@ -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<number>`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<number>`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 },
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue