add loading and optimize query using cache and pwa

This commit is contained in:
2026-05-20 16:08:29 +07:00
parent 5d095151e4
commit ef7aa528d4
8 changed files with 134 additions and 3 deletions
+8 -2
View File
@@ -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)) {