1- import crypto from 'crypto ' ;
1+ import { xxh3 } from '@node-rs/xxhash ' ;
22import R from 'ramda' ;
33import { createQuery , compile , queryClass , PreAggregations , QueryFactory } from '@cubejs-backend/schema-compiler' ;
44import { 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
@@ -523,10 +523,7 @@ export class CompilerApi {
523523 }
524524
525525 mixInVisibilityMaskHash ( compilerId , visibilityMaskHash ) {
526- const uuidBytes = uuidParse ( compilerId ) ;
527- const hashBytes = Buffer . from ( visibilityMaskHash , 'hex' ) ;
528- return uuidv4 ( { random : crypto . createHash ( 'sha256' ) . update ( uuidBytes ) . update ( hashBytes ) . digest ( )
529- . subarray ( 0 , 16 ) } ) ;
526+ return uuidv4 ( { random : Buffer . from ( xxh3 . xxh64 ( `${ compilerId } ${ visibilityMaskHash } ` ) . toString ( 16 ) , 'hex' ) } ) ;
530527 }
531528
532529 async metaConfig ( requestContext , options = { } ) {
@@ -542,8 +539,8 @@ export class CompilerApi {
542539 return {
543540 cubes : patchedCubes ,
544541 // This compilerId is primarily used by the cubejs-backend-native or caching purposes.
545- // By default it doesn't account for member visibility changes introduced above by DAP.
546- // Here we're modifying the originila compilerId in a way that it's distinct for
542+ // By default, it doesn't account for member visibility changes introduced above by DAP.
543+ // Here we're modifying the original compilerId in a way that it's distinct for
547544 // distinct schema versions while still being a valid UUID.
548545 compilerId : visibilityMaskHash ? this . mixInVisibilityMaskHash ( compilers . compilerId , visibilityMaskHash ) : compilers . compilerId ,
549546 } ;
0 commit comments