perf: reduce widget and runtime overhead
This commit is contained in:
1 parent
5a7607ddf7
commit
14c7e58e17
33 files changed
+779
-339
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import { beforeEach, describe, expect, test, vi } from "vitest";
|
||||
|
||||
import { mediaTranscodingRequestHandler } from "./media-transcoding";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
createIntegrationAsync: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@homarr/integrations", () => ({
|
||||
createIntegrationAsync: mocks.createIntegrationAsync,
|
||||
}));
|
||||
|
||||
const integration = {
|
||||
id: "tdarr-integration",
|
||||
kind: "tdarr",
|
||||
} as Parameters<typeof mediaTranscodingRequestHandler.handler>[0];
|
||||
|
||||
describe("mediaTranscodingRequestHandler", () => {
|
||||
beforeEach(() => {
|
||||
mediaTranscodingRequestHandler.invalidateCache();
|
||||
mocks.createIntegrationAsync.mockReset();
|
||||
});
|
||||
|
||||
test("starts independent upstream requests together", async () => {
|
||||
const requestsStarted = Promise.withResolvers<void>();
|
||||
const getQueueAsync = vi.fn(async () => {
|
||||
await requestsStarted.promise;
|
||||
return { array: [], totalCount: 0, startIndex: 0, endIndex: 0 };
|
||||
});
|
||||
const getWorkersAsync = vi.fn(async () => {
|
||||
await requestsStarted.promise;
|
||||
return [];
|
||||
});
|
||||
const getStatisticsAsync = vi.fn(async () => {
|
||||
await requestsStarted.promise;
|
||||
return {};
|
||||
});
|
||||
mocks.createIntegrationAsync.mockResolvedValue({ getQueueAsync, getWorkersAsync, getStatisticsAsync });
|
||||
|
||||
const resultPromise = mediaTranscodingRequestHandler
|
||||
.handler(integration, { pageOffset: 0, pageSize: 10 })
|
||||
.getDataAsync();
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(getQueueAsync).toHaveBeenCalledOnce();
|
||||
expect(getWorkersAsync).toHaveBeenCalledOnce();
|
||||
expect(getStatisticsAsync).toHaveBeenCalledOnce();
|
||||
});
|
||||
requestsStarted.resolve();
|
||||
await resultPromise;
|
||||
});
|
||||
});
|
||||
@@ -11,10 +11,15 @@ export const mediaTranscodingRequestHandler = createIntegrationRequestHandler<
|
||||
>({
|
||||
async requestAsync(integration, input) {
|
||||
const integrationInstance = await createIntegrationAsync(integration);
|
||||
const [queue, workers, statistics] = await Promise.all([
|
||||
integrationInstance.getQueueAsync(input.pageOffset, input.pageSize),
|
||||
integrationInstance.getWorkersAsync(),
|
||||
integrationInstance.getStatisticsAsync(),
|
||||
]);
|
||||
return {
|
||||
queue: await integrationInstance.getQueueAsync(input.pageOffset, input.pageSize),
|
||||
workers: await integrationInstance.getWorkersAsync(),
|
||||
statistics: await integrationInstance.getStatisticsAsync(),
|
||||
queue,
|
||||
workers,
|
||||
statistics,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user