Skip to content

Commit

Permalink
⚡️ add undici for uber fast webdis requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredkiss3 committed Feb 11, 2024
1 parent ad8d457 commit c5bd2c4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"sharp": "^0.32.5",
"tailwind-merge": "^1.14.0",
"text-field-edit": "^4.0.0",
"undici": "^6.6.2",
"vfile": "^6.0.1",
"zod": "^3.22.2",
"zod-form-data": "^2.0.1",
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions src/lib/server/kv/webdis.server.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
import { _envObject as env } from "../../../env-config.mjs";

import { request } from "undici";
/**
* @typedef {import("./index.server").KVStore} KVStore
*/
Expand Down Expand Up @@ -58,22 +58,20 @@ export class WebdisKV {

const rand = Math.ceil(Math.random() * 10e15);
console.time(`[${rand} webdis] ${fullURL}`);
return await fetch(fullURL, {
return await request(fullURL, {
method: "PUT",
cache: "no-store",
headers: {
Authorization: `Basic ${btoa(authString)}`
},
body: body ?? undefined
}).then((r) =>
r.text().then((text) => {
if (!r.ok) {
}).then(({ body, statusCode }) =>
body.text().then((text) => {
if (statusCode !== 200) {
console.log(
"Couldn't fetch from webdis KV, received this response from server : ",
{
text,
status: r.status,
statusText: r.statusText
status: statusCode
}
);
}
Expand Down

0 comments on commit c5bd2c4

Please sign in to comment.