-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37118df
commit 48be339
Showing
18 changed files
with
849 additions
and
2,844 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,45 @@ | ||
import {prisma} from "@repo/db"; | ||
import {memoize} from "nextjs-better-unstable-cache"; | ||
import { prisma } from "@repo/db"; | ||
import { memoize } from "nextjs-better-unstable-cache"; | ||
|
||
export const getCachedSolutionsPosted = memoize( | ||
async (username: string) => | ||
await prisma.solution.findMany({where: {author: {username}}}), | ||
{ | ||
revalidateTags: (username) => [`solutions::${username}`], | ||
log: ["verbose", "datacache", "dedupe"], | ||
logid: "getCachedSolutionsPosted", | ||
} | ||
async (username: string) => | ||
await prisma.solution.findMany({ where: { author: { username } } }), | ||
{ | ||
revalidateTags: (username) => [`solutions::${username}`], | ||
log: ["verbose", "datacache", "dedupe"], | ||
logid: "getCachedSolutionsPosted", | ||
} | ||
); | ||
|
||
export const getCachedSolution = memoize( | ||
async (id: string) => | ||
await prisma.solution.findFirst({ | ||
where: { | ||
id: id, | ||
}, | ||
include: { | ||
author: { | ||
select: { | ||
username: true, | ||
name: true, | ||
}, | ||
}, | ||
files: true, | ||
challenge: { | ||
select: { | ||
slug: true, | ||
track: { | ||
select: { | ||
slug: true, | ||
}, | ||
}, | ||
initialFiles:true, | ||
}, | ||
}, | ||
}, | ||
}), | ||
{ | ||
revalidateTags: (id) => [`solution::${id}`], | ||
log: ["verbose", "datacache", "dedupe"], | ||
logid: "getCachedSolution", | ||
} | ||
); | ||
|
||
|
||
export const getCachedSolutions = memoize(async (trackSlug: string|null, challengeSlug: string|null, orderBy: "asc" | "desc" | null | ||
) => await prisma.solution.findMany({ | ||
orderBy: [ | ||
{ | ||
createdAt: orderBy || "desc" | ||
} | ||
], | ||
where: { | ||
async (id: string) => | ||
await prisma.solution.findFirst({ | ||
where: { | ||
id: id, | ||
}, | ||
include: { | ||
author: { | ||
select: { | ||
username: true, | ||
name: true, | ||
}, | ||
}, | ||
files: true, | ||
challenge: { | ||
// passing null with check if slug is null | ||
slug: challengeSlug || undefined, | ||
select: { | ||
slug: true, | ||
track: { | ||
slug: trackSlug || undefined, | ||
} | ||
} | ||
},include:{ | ||
challenge:{ | ||
select:{ | ||
label:true,slug:true, | ||
track:{ | ||
select:{ | ||
name:true, | ||
slug:true, | ||
} | ||
} | ||
select: { | ||
slug: true, | ||
}, | ||
}, | ||
} | ||
} | ||
}), { | ||
revalidateTags: (trackSlug: string|null, challengeSlug: string|null, orderBy: "asc" | "desc" | null) => [`solutions::${trackSlug}::${challengeSlug}::${orderBy}`], | ||
}, | ||
}, | ||
}, | ||
}), | ||
{ | ||
revalidateTags: (id) => [`solution::${id}`], | ||
log: ["verbose", "datacache", "dedupe"], | ||
logid: "getCachedSolution", | ||
}) | ||
} | ||
); |
Oops, something went wrong.