mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 00:18:19 +01:00
feat(api): ✨ Add timeline benchmark
This commit is contained in:
parent
3ec5118771
commit
19d8680289
44
benchmarks/timeline.ts
Normal file
44
benchmarks/timeline.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import type { Status as ApiStatus } from "@versia/client/types";
|
||||
import { fakeRequest, getTestStatuses, getTestUsers } from "~/tests/utils";
|
||||
import { run, bench } from "mitata";
|
||||
import { configureLoggers } from "@/loggers";
|
||||
|
||||
await configureLoggers(true);
|
||||
|
||||
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
||||
await getTestStatuses(40, users[0]);
|
||||
|
||||
const testTimeline = async (): Promise<void> => {
|
||||
const response = await fakeRequest("/api/v1/timelines/home", {
|
||||
headers: {
|
||||
Authorization: `Bearer ${tokens[0].data.accessToken}`,
|
||||
},
|
||||
});
|
||||
|
||||
const objects = (await response.json()) as ApiStatus[];
|
||||
|
||||
if (objects.length !== 20) {
|
||||
throw new Error("Invalid response (not 20 objects)");
|
||||
}
|
||||
};
|
||||
|
||||
const testInstance = async (): Promise<void> => {
|
||||
const response = await fakeRequest("/api/v2/instance", {
|
||||
headers: {
|
||||
Authorization: `Bearer ${tokens[0].data.accessToken}`,
|
||||
},
|
||||
});
|
||||
|
||||
const object = (await response.json()) as Record<string, unknown>;
|
||||
|
||||
if (typeof object !== "object") {
|
||||
throw new Error("Invalid response (not an object)");
|
||||
}
|
||||
};
|
||||
|
||||
bench("timeline", testTimeline).range("amount", 1, 1000);
|
||||
bench("instance", testInstance).range("amount", 1, 1000);
|
||||
|
||||
await run();
|
||||
|
||||
await deleteUsers();
|
||||
|
|
@ -91,6 +91,7 @@
|
|||
"oclif": "^4.15.20",
|
||||
"ts-prune": "^0.10.3",
|
||||
"typescript": "^5.6.3",
|
||||
"vitepress": "^1.5.0",
|
||||
"zod-to-json-schema": "^3.23.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
|
@ -138,6 +139,7 @@
|
|||
"markdown-it-container": "^4.0.0",
|
||||
"markdown-it-toc-done-right": "^4.2.0",
|
||||
"mime-types": "^2.1.35",
|
||||
"mitata": "^1.0.10",
|
||||
"oauth4webapi": "^3.1.2",
|
||||
"ora": "^8.1.1",
|
||||
"pg": "^8.13.1",
|
||||
|
|
|
|||
Loading…
Reference in a new issue