Skip to content

Commit 5038860

Browse files
committed
use xxh3 in query-orchestrator package
1 parent d23446e commit 5038860

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

packages/cubejs-query-orchestrator/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@cubejs-backend/base-driver": "1.2.27",
3333
"@cubejs-backend/cubestore-driver": "1.2.27",
3434
"@cubejs-backend/shared": "1.2.27",
35+
"@node-rs/xxhash": "^1.7.6",
3536
"csv-write-stream": "^2.0.0",
3637
"generic-pool": "^3.8.2",
3738
"lru-cache": "^5.1.1",

packages/cubejs-query-orchestrator/src/orchestrator/PreAggregations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import R from 'ramda';
2-
import crypto from 'crypto';
2+
import { xxh3 } from '@node-rs/xxhash';
33
import { getEnv, } from '@cubejs-backend/shared';
44

55
import { BaseDriver, InlineTable, } from '@cubejs-backend/base-driver';
@@ -29,7 +29,7 @@ export function version(cacheKey) {
2929
let result = '';
3030

3131
const hashCharset = 'abcdefghijklmnopqrstuvwxyz012345';
32-
const digestBuffer = crypto.createHash('md5').update(JSON.stringify(cacheKey)).digest();
32+
const digestBuffer = Buffer.from(xxh3.xxh64(JSON.stringify(cacheKey)).toString(16), 'hex');
3333

3434
let residue = 0;
3535
let shiftCounter = 0;

packages/cubejs-query-orchestrator/src/orchestrator/utils.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import crypto from 'crypto';
1+
import { xxh3 } from '@node-rs/xxhash';
22

33
import { getProcessUid } from '@cubejs-backend/shared';
44
import { QueryKey, QueryKeyHash } from '@cubejs-backend/base-driver';
@@ -18,16 +18,11 @@ export function getCacheHash(queryKey: QueryKey | CacheKey, processUid?: string)
1818
return queryKey as any;
1919
}
2020

21+
const hash = xxh3.xxh128(JSON.stringify(queryKey)).toString(16);
22+
2123
if (typeof queryKey === 'object' && 'persistent' in queryKey && queryKey.persistent) {
22-
return `${crypto
23-
.createHash('md5')
24-
.update(JSON.stringify(queryKey))
25-
.digest('hex')
26-
}@${processUid}` as any;
24+
return `${hash}@${processUid}` as any;
2725
} else {
28-
return crypto
29-
.createHash('md5')
30-
.update(JSON.stringify(queryKey))
31-
.digest('hex') as any;
26+
return hash as any;
3227
}
3328
}

0 commit comments

Comments
 (0)