Skip to content

Commit

Permalink
Reduce transfer size
Browse files Browse the repository at this point in the history
  • Loading branch information
Mansive committed Jan 6, 2024
1 parent aad1bb2 commit d5840e2
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/app/api/search/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,26 @@ export async function GET(request: NextRequest) {
);
}

const results = await xata.db.Books.search(searchParams, {
target: ["title"],
fuzziness: 0,
page: { size: 50, offset: 0 },
});
try {
const results = await xata.db.Books.search(searchParams, {
target: ["title"],
fuzziness: 0,
page: { size: 50, offset: 0 },
});

return NextResponse.json(results);
// Pasted from Copilot; could probably be done better
const records = JSON.parse(JSON.stringify(results))["records"];
records.forEach((book: Record<string, any>) => {
delete book.id;
delete book.embeddings;
delete book.xata;
});

return NextResponse.json({ records });
} catch (error) {
return NextResponse.json(
{ message: "A strange error has ocurred" },
{ status: 500 }
);
}
}

0 comments on commit d5840e2

Please sign in to comment.