Skip to content

Commit

Permalink
Merge pull request #67 from route06inc/fix-over-2mb-data-cache
Browse files Browse the repository at this point in the history
Fix ` Error: Failed to set Next.js data cache, items over 2MB can not be cached (2865842 bytes) at IncrementalCache.set` error on development
  • Loading branch information
satococoa authored Nov 1, 2024
2 parents a019f60 + d6621ef commit da15ab0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
14 changes: 1 addition & 13 deletions app/(main)/agents/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getTeamMembershipByAgentId } from "@/app/(auth)/lib/get-team-membership-by-agent-id";
import { getUser } from "@/lib/supabase";
import { createAgent, getAgents } from "@/services/agents";
import { CreateAgentButton } from "@/services/agents/components";
Expand All @@ -9,18 +8,7 @@ type AgentListProps = {
userId: string;
};
async function AgentList(props: AgentListProps) {
const allAgents = await getAgents({ userId: props.userId });
const agents = (
await Promise.all(
allAgents.map(async (agent) => {
const teamMembership = await getTeamMembershipByAgentId(
agent.id,
props.userId,
);
return teamMembership ? agent : null;
}),
)
).filter((v) => v != null);
const agents = await getAgents({ userId: props.userId });

return (
<div className="flex flex-col gap-2">
Expand Down
19 changes: 17 additions & 2 deletions services/agents/actions/get-agent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use server";

import { agents, db } from "@/drizzle";
import { agents, db, supabaseUserMappings, teamMemberships } from "@/drizzle";
import { eq } from "drizzle-orm";
import { revalidateTag, unstable_cache } from "next/cache";
import type { AgentId } from "../types";
Expand All @@ -17,7 +17,22 @@ const getAgentsTag = (params: TagParams) => `${params.userId}.getAgents`;

export const getAgents = async (args: GetAgentsArgs) => {
const cachedAgents = unstable_cache(
() => db.select().from(agents),
async () => {
const result = await db
.select({ agents })
.from(agents)
.innerJoin(
teamMemberships,
eq(agents.teamDbId, teamMemberships.teamDbId),
)
.innerJoin(
supabaseUserMappings,
eq(teamMemberships.userDbId, supabaseUserMappings.userDbId),
)
.where(eq(supabaseUserMappings.supabaseUserId, args.userId));

return result.map((row) => row.agents);
},
[args.userId],
{ tags: [getAgentsTag(args)] },
);
Expand Down

0 comments on commit da15ab0

Please sign in to comment.