mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-29 07:21:16 -07:00
Performance: reduce json data transformations (#7175)
This commit is contained in:
@@ -8,10 +8,13 @@ const widget = {
|
||||
mappings: {
|
||||
workers: {
|
||||
endpoint: "workers/status",
|
||||
map: (data) => ({
|
||||
total_workers: asJson(data).workers_status.length,
|
||||
active_workers: asJson(data).workers_status.filter((worker) => !worker.idle).length,
|
||||
}),
|
||||
map: (data) => {
|
||||
const workers = asJson(data).workers_status;
|
||||
return {
|
||||
total_workers: workers.length,
|
||||
active_workers: workers.filter((worker) => !worker.idle).length,
|
||||
};
|
||||
},
|
||||
},
|
||||
pending: {
|
||||
method: "POST",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { describe, it } from "vitest";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { expectWidgetConfigShape } from "test-utils/widget-config";
|
||||
|
||||
@@ -8,4 +8,12 @@ describe("unmanic widget config", () => {
|
||||
it("exports a valid widget config", () => {
|
||||
expectWidgetConfigShape(widget);
|
||||
});
|
||||
|
||||
it("counts total and active workers", () => {
|
||||
const result = widget.mappings.workers.map(
|
||||
Buffer.from(JSON.stringify({ workers_status: [{ idle: true }, { idle: false }, { idle: false }] })),
|
||||
);
|
||||
|
||||
expect(result).toEqual({ total_workers: 3, active_workers: 2 });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user