add loading and optimize query using cache and pwa
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { cache } from "react";
|
||||
import { Prisma } from "@/app/generated/prisma/client";
|
||||
import type { ActivityCategory, Vibe } from "@/app/generated/prisma/enums";
|
||||
import { tripRepo, type TripFilters } from "@/server/repositories/trip.repo";
|
||||
@@ -38,13 +39,18 @@ export const tripService = {
|
||||
return tripRepo.findAll();
|
||||
},
|
||||
|
||||
async getTripById(id: string) {
|
||||
/**
|
||||
* Ambil trip by id. Dibungkus `React.cache()` — `generateMetadata`, body
|
||||
* halaman, dan `opengraph-image` memanggil ini untuk id yang sama dalam satu
|
||||
* request, jadi query Prisma yang berat ini cukup jalan sekali per request.
|
||||
*/
|
||||
getTripById: cache(async (id: string) => {
|
||||
const trip = await tripRepo.findById(id);
|
||||
if (!trip) {
|
||||
throw new Error("Trip tidak ditemukan");
|
||||
}
|
||||
return trip;
|
||||
},
|
||||
}),
|
||||
|
||||
async createTrip(input: CreateTripInput) {
|
||||
if (isTripDepartureDayPast(input.date)) {
|
||||
|
||||
Reference in New Issue
Block a user