Skip to content

Commit d23446e

Browse files
committed
use xxh3 in server-core package
1 parent 8c4566c commit d23446e

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

packages/cubejs-server-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@cubejs-backend/schema-compiler": "1.2.27",
3838
"@cubejs-backend/shared": "1.2.27",
3939
"@cubejs-backend/templates": "1.2.27",
40+
"@node-rs/xxhash": "^1.7.6",
4041
"codesandbox-import-utils": "^2.1.12",
4142
"cross-spawn": "^7.0.1",
4243
"fs-extra": "^8.1.0",

packages/cubejs-server-core/src/core/CompilerApi.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import crypto from 'crypto';
1+
import { xxh3, Xxh3 } from '@node-rs/xxhash';
22
import R from 'ramda';
33
import { createQuery, compile, queryClass, PreAggregations, QueryFactory } from '@cubejs-backend/schema-compiler';
44
import { v4 as uuidv4, parse as uuidParse, stringify as uuidStringify } from 'uuid';
@@ -55,7 +55,7 @@ export class CompilerApi {
5555

5656
if (this.options.devServer || this.options.fastReload) {
5757
const files = await this.repository.dataSchemaFiles();
58-
compilerVersion += `_${crypto.createHash('md5').update(JSON.stringify(files)).digest('hex')}`;
58+
compilerVersion += `_${xxh3.xxh64(JSON.stringify(files)).toString(16)}`;
5959
}
6060

6161
if (!this.compilers || this.compilerVersion !== compilerVersion) {
@@ -224,7 +224,7 @@ export class CompilerApi {
224224

225225
hashRequestContext(context) {
226226
if (!context.__hash) {
227-
context.__hash = crypto.createHash('md5').update(JSON.stringify(context)).digest('hex');
227+
context.__hash = xxh3.xxh64(JSON.stringify(context)).toString(16);
228228
}
229229
return context.__hash;
230230
}
@@ -505,7 +505,7 @@ export class CompilerApi {
505505
const visibiliyMask = JSON.stringify(isMemberVisibleInContext, Object.keys(isMemberVisibleInContext).sort());
506506
// This hash will be returned along the modified meta config and can be used
507507
// to distinguish between different "schema versions" after DAP visibility is applied
508-
const visibilityMaskHash = crypto.createHash('sha256').update(visibiliyMask).digest('hex');
508+
const visibilityMaskHash = xxh3.xxh64(visibiliyMask).toString(16);
509509

510510
return {
511511
cubes: cubes
@@ -525,8 +525,8 @@ export class CompilerApi {
525525
mixInVisibilityMaskHash(compilerId, visibilityMaskHash) {
526526
const uuidBytes = uuidParse(compilerId);
527527
const hashBytes = Buffer.from(visibilityMaskHash, 'hex');
528-
return uuidv4({ random: crypto.createHash('sha256').update(uuidBytes).update(hashBytes).digest()
529-
.subarray(0, 16) });
528+
return uuidv4({ random: Buffer.from(new Xxh3().update(uuidBytes).update(hashBytes).digest()
529+
.toString(16), 'hex').subarray(0, 16) });
530530
}
531531

532532
async metaConfig(requestContext, options = {}) {

packages/cubejs-server-core/src/core/RefreshScheduler.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import R from 'ramda';
22
import pLimit from 'p-limit';
33
import { v4 as uuidv4 } from 'uuid';
4-
import crypto from 'crypto';
4+
import { xxh3 } from '@node-rs/xxhash';
55
import { Required } from '@cubejs-backend/shared';
66
import {
77
PreAggregationDescription,
@@ -127,10 +127,7 @@ function getPreAggsJobsList(
127127
* Returns MD5 hash token of the job object.
128128
*/
129129
function getPreAggJobToken(job: PreAggJob) {
130-
return crypto
131-
.createHash('md5')
132-
.update(JSON.stringify(job))
133-
.digest('hex');
130+
return xxh3.xxh64(JSON.stringify(job)).toString(16);
134131
}
135132

136133
export class RefreshScheduler {

0 commit comments

Comments
 (0)