The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
chore: replace lodash.orderby with inline function (#81160)
Uladzimir Havenchykdff2fd94ce91
diff --git a/bun.lock b/bun.lockindex 35b75e0cdae..a20a52c2206 100644--- a/bun.lock+++ b/bun.lock@@ -110,7 +110,6 @@"leaflet": "^1.2.0","leaflet-draw": "^0.4.9","lodash.debounce": "^4.0.8",- "lodash.orderby": "^4.6.0","marked": "18.0.6","mustache": "^2.3.2","normalizr": "^3.0.2",@@ -228,7 +227,6 @@"@types/leaflet": "^1.7.5","@types/leaflet-draw": "^0.4.14","@types/lodash.debounce": "^4.0.9",- "@types/lodash.orderby": "^4.6.9","@types/micromatch": "^4.0.10","@types/mustache": "^4.1.2","@types/postcss-import": "^14.0.3",@@ -1870,8 +1868,6 @@"@types/lodash.debounce": ["@types/[email protected]", "", { "dependencies": { "@types/lodash": "*" } }, "sha512-Ma5JcgTREwpLRwMM+XwBR7DaWe96nC38uCBDFKZWbNKD+osjVzdpnUSwBcqCptrp16sSOLBAUb50Car5I0TCsQ=="],- "@types/lodash.orderby": ["@types/[email protected]", "", { "dependencies": { "@types/lodash": "*" } }, "sha512-T9o2wkIJOmxXwVTPTmwJ59W6eTi2FseiLR369fxszG649Po/xe9vqFNhf/MtnvT5jrbDiyWKxPFPZbpSVK0SVQ=="],-"@types/markdown-it": ["@types/[email protected]", "", { "dependencies": { "@types/linkify-it": "^5", "@types/mdurl": "^2" } }, "sha512-promo4eFwuiW+TfGxhi+0x3czqTYJkG8qB17ZUJiVF10Xm7NLVRSLUsfRTU/6h1e24VvRnXCx+hG7li58lkzog=="],"@types/mdast": ["@types/[email protected]", "", { "dependencies": { "@types/unist": "*" } }, "sha512-LsjtqsyF+d2/yFOYaN22dHZI1Cpwkrj+g06G8+qtUKlhovPW89YhqSnfKtMbkgmEtYpH2gydRNULd6y8mciAFg=="],@@ -3870,8 +3866,6 @@"lodash.once": ["[email protected]", "", {}, "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg=="],- "lodash.orderby": ["[email protected]", "", {}, "sha512-T0rZxKmghOOf5YPnn8EY5iLYeWCpZq8G41FfqoVHH5QDTAFaghJRmAdLiadEDq+ztgM2q5PjA+Z1fOwGrLgmtg=="],-"lodash.throttle": ["[email protected]", "", {}, "sha512-wIkUCfVKpVsWo3JSZlc+8MB5it+2AN5W8J7YVMST30UrvcQNZ1Okbj+rbVniijTWE6FGYy4XJq/rHkas8qJMLQ=="],"lodash.truncate": ["[email protected]", "", {}, "sha1-WjUNoLERO4N+z//VgSy+WNbq4ZM="],diff --git a/eslint.config.mjs b/eslint.config.mjsindex a0f099d0a5e..ce7319dcb22 100644--- a/eslint.config.mjs+++ b/eslint.config.mjs@@ -337,7 +337,6 @@ const configs = [{allowed: ["underscore",- "lodash.orderby","lodash.debounce","chalk","node-fetch",diff --git a/frontend/src/metabase/monitor/tools/components/Logs/utils.ts b/frontend/src/metabase/monitor/tools/components/Logs/utils.tsindex ac739482290..83a6c582492 100644--- a/frontend/src/metabase/monitor/tools/components/Logs/utils.ts+++ b/frontend/src/metabase/monitor/tools/components/Logs/utils.ts@@ -1,4 +1,3 @@-import orderBy from "lodash.orderby";import _ from "underscore";import {@@ -41,13 +40,20 @@ function logEventKey(ev: Log) {return `${ev.timestamp}, ${ev.process_uuid}, ${ev.fqns}, ${ev.msg}`;}+function compareAsc(a: string, b: string) {+ return a < b ? -1 : a > b ? 1 : 0;+}+export function mergeLogs(logArrays: Log[][]) {let prevLogKey = "";- return orderBy(- logArrays.flat(),- ["timestamp", "process_uuid", "msg"],- ["asc", "asc", "asc"],- )+ return logArrays+ .flat()+ .toSorted(+ (a, b) =>+ compareAsc(a.timestamp, b.timestamp) ||+ compareAsc(a.process_uuid, b.process_uuid) ||+ compareAsc(a.msg, b.msg),+ ).filter((log) => {const key = logEventKey(log);const keep = prevLogKey !== key;diff --git a/frontend/src/metabase/monitor/tools/components/Logs/utils.unit.spec.ts b/frontend/src/metabase/monitor/tools/components/Logs/utils.unit.spec.tsnew file mode 100644index 00000000000..a498097c1fc--- /dev/null+++ b/frontend/src/metabase/monitor/tools/components/Logs/utils.unit.spec.ts@@ -0,0 +1,56 @@+import type { Log } from "metabase-types/api";++import { mergeLogs } from "./utils";++function createLog(log: Partial<Log> = {}): Log {+ return {+ timestamp: "2024-01-10T21:21:58.597Z",+ level: "DEBUG",+ fqns: "metabase.server.middleware.log",+ msg: "GET /api/collection/root 200",+ exception: null,+ process_uuid: "e7774ef2-42ab-43de-89f7-d6de9fdc624f",+ ...log,+ };+}++describe("mergeLogs", () => {+ it("merges logs from several arrays, oldest first", () => {+ const first = createLog({ timestamp: "2024-01-10T21:21:58.001Z" });+ const second = createLog({ timestamp: "2024-01-10T21:21:58.002Z" });+ const third = createLog({ timestamp: "2024-01-10T21:21:58.003Z" });++ expect(mergeLogs([[third], [first, second]])).toEqual([+ first,+ second,+ third,+ ]);+ });++ it("drops duplicates when polled batches overlap", () => {+ const older = createLog({ timestamp: "2024-01-10T21:21:58.001Z" });+ const newer = createLog({ timestamp: "2024-01-10T21:21:58.002Z" });+ const newest = createLog({ timestamp: "2024-01-10T21:21:58.003Z" });++ expect(+ mergeLogs([+ [older, newer],+ [newer, newest],+ ]),+ ).toEqual([older, newer, newest]);+ });++ it("keeps logs that are not exact duplicates", () => {+ const timestamp = "2024-01-10T21:21:58.597Z";+ const log = createLog({ timestamp });+ const sameTimeOtherMessage = createLog({ timestamp, msg: "other message" });+ const sameTimeOtherNamespace = createLog({+ timestamp,+ fqns: "metabase.db",+ });++ expect(+ mergeLogs([[log], [sameTimeOtherMessage], [sameTimeOtherNamespace]]),+ ).toHaveLength(3);+ });+});diff --git a/package.json b/package.jsonindex e15933b5b3d..28dc8e1348f 100644--- a/package.json+++ b/package.json@@ -119,7 +119,6 @@"leaflet": "^1.2.0","leaflet-draw": "^0.4.9","lodash.debounce": "^4.0.8",- "lodash.orderby": "^4.6.0","marked": "18.0.6","mustache": "^2.3.2","normalizr": "^3.0.2",@@ -237,7 +236,6 @@"@types/leaflet": "^1.7.5","@types/leaflet-draw": "^0.4.14","@types/lodash.debounce": "^4.0.9",- "@types/lodash.orderby": "^4.6.9","@types/micromatch": "^4.0.10","@types/mustache": "^4.1.2","@types/postcss-import": "^14.0.3",