-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Align dev server with CF Pages behavior
- Loading branch information
1 parent
6ae6c40
commit 728fd7b
Showing
4 changed files
with
28 additions
and
41 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 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 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 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,49 +1,35 @@ | ||
import moment from "moment/moment"; | ||
import { prisma } from "../server/db"; | ||
|
||
const queryCache = new Map(); | ||
const roomFilter = { | ||
published: true, | ||
AND: { | ||
closesAt: { | ||
gt: moment().subtract(1, "day").toDate(), | ||
}, | ||
}, | ||
}; | ||
|
||
export async function findPublishedRooms() { | ||
const rooms = await prisma.waitingRoom.findMany({ | ||
where: { | ||
published: true, | ||
AND: { | ||
closesAt: { | ||
gt: moment().subtract(1, "day").toDate(), | ||
}, | ||
}, | ||
}, | ||
return prisma.waitingRoom.findMany({ | ||
where: roomFilter, | ||
include: { | ||
owner: true, | ||
}, | ||
orderBy: { | ||
closesAt: "asc", | ||
}, | ||
}); | ||
|
||
rooms.forEach((room) => { | ||
queryCache.set(room.id, room); | ||
}); | ||
|
||
return rooms; | ||
} | ||
|
||
export async function findRoomById(id: string) { | ||
async function getRoomById() { | ||
return prisma.waitingRoom.findUniqueOrThrow({ | ||
where: { | ||
id, | ||
}, | ||
include: { | ||
owner: true, | ||
}, | ||
}); | ||
} | ||
|
||
if (queryCache.has(id)) { | ||
return queryCache.get(id) as Awaited<ReturnType<typeof getRoomById>>; | ||
} | ||
const room = await getRoomById(); | ||
queryCache.set(room.id, room); | ||
return room; | ||
return prisma.waitingRoom.findFirst({ | ||
where: { | ||
id, | ||
...roomFilter, | ||
}, | ||
include: { | ||
owner: true, | ||
}, | ||
}); | ||
} |