Refactor most getServerProps to fetch independent request in parallel and projected the data only to return the necessary fields and changed some functions
This commit is contained in:
@@ -21,11 +21,12 @@ export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
|
||||
if (!user) return redirect("/login")
|
||||
|
||||
const entityIDs = mapBy(user.entities, 'id')
|
||||
const entities = await getEntitiesWithRoles(isAdmin(user) ? undefined : entityIDs)
|
||||
|
||||
const domain = user.email.split("@").pop()
|
||||
const discounts = await db.collection<Discount>("discounts").find({ domain }).toArray()
|
||||
const packages = await db.collection<Package>("packages").find().toArray()
|
||||
const [entities, discounts, packages] = await Promise.all([
|
||||
getEntitiesWithRoles(isAdmin(user) ? undefined : entityIDs),
|
||||
db.collection<Discount>("discounts").find({ domain }).toArray(),
|
||||
db.collection<Package>("packages").find().toArray(),
|
||||
])
|
||||
|
||||
return {
|
||||
props: serialize({ user, entities, discounts, packages }),
|
||||
|
||||
Reference in New Issue
Block a user