calculate how fucked we are

This commit is contained in:
Dhravya Shah 2024-08-03 18:31:55 -07:00
parent e30e9f4e0b
commit a327805a7d
2 changed files with 43 additions and 2 deletions

View file

@ -666,4 +666,45 @@ app.get(
},
);
app.get("/howFuckedAreWe", async (c) => {
let keys = 0;
const concurrencyLimit = 5; // Adjust this based on your system's capability
const queue: string[] = [undefined]; // Start with an undefined cursor
async function fetchKeys(cursor?: string): Promise<void> {
const response = await c.env.KV.list({ cursor });
keys += response.keys.length;
// @ts-ignore
if (response.cursor) {
// @ts-ignore
queue.push(response.cursor);
}
}
async function getAllKeys(): Promise<void> {
const promises: Promise<void>[] = [];
while (queue.length > 0) {
while (promises.length < concurrencyLimit && queue.length > 0) {
const cursor = queue.shift();
promises.push(fetchKeys(cursor));
}
await Promise.all(promises);
promises.length = 0; // Clear the promises array
}
}
await getAllKeys();
console.log(`Total number of keys: ${keys}`);
// on a scale of 200,000
// what % are we there?
const fuckedPercent = (keys / 200000) * 100;
return c.json({ fuckedPercent });
});
export default app;

View file

@ -68,9 +68,9 @@ bot.on("message", async (ctx) => {
if (response.status !== 200) {
console.log("Failed to get response from backend");
console.log(response.status);
console.log(await response.text());
await ctx.reply(
"Sorry, I am not able to process your request at the moment.",
"Sorry, I am not able to process your request at the moment." +
(await response.text()),
);
return;
}