diff --git a/app/api/stats/historical-volume-kv/route.ts b/app/api/stats/historical-volume-kv/route.ts index 0302cb45..736f895b 100644 --- a/app/api/stats/historical-volume-kv/route.ts +++ b/app/api/stats/historical-volume-kv/route.ts @@ -24,10 +24,29 @@ export async function GET(req: NextRequest) { try { const allKeys = await getAllSetMembers(kv, HISTORICAL_VOLUME_SET_KEY) - // Use pipelining to fetch all data in a single round-trip - const pipeline = kv.pipeline() - allKeys.forEach((key) => pipeline.get(key)) - const data = await pipeline.exec() + // Fetch all values for the keys using individual GET requests + const data = await Promise.all( + allKeys.map(async (key) => { + const response = await fetch( + `${process.env.KV_REST_API_URL}/get/${key}`, + { + headers: { + Authorization: `Bearer ${process.env.KV_REST_API_TOKEN}`, + }, + cache: "no-store", + }, + ) + + if (!response.ok) { + throw new Error( + `HTTP error! status: ${response.status} for key: ${key}`, + ) + } + + const { result } = await response.json() + return JSON.parse(result) as VolumeDataPoint + }), + ) const volumeData: VolumeDataPoint[] = [] let startTimestamp = Infinity diff --git a/app/stats/hooks/use-volume-data.ts b/app/stats/hooks/use-volume-data.ts index 9b6b3cb7..39f24226 100644 --- a/app/stats/hooks/use-volume-data.ts +++ b/app/stats/hooks/use-volume-data.ts @@ -26,7 +26,9 @@ export function useVolumeData(): UseHistoricalVolumeResult { } export async function getHistoricalVolume(): Promise { - const res = await fetch("/api/stats/historical-volume-kv", { cache: 'no-store' }) + const res = await fetch("/api/stats/historical-volume-kv", { + cache: "no-store", + }) if (!res.ok) { throw new Error(`Failed to fetch historical volume data: ${res.statusText}`)