cube-js / cube

📊 Cube — Universal semantic layer platform for AI, BI, spreadsheets, and embedded analytics
https://cube.dev
Other
18.02k stars 1.78k forks source link

Dynamic data models with JavaScript #9007

Open tiger-feng opened 1 day ago

tiger-feng commented 1 day ago

Describe the bug Each time the data model is compiled, asyncModule is called three times

Expected behavior Each time the data model is compiled, asyncModule is called three times. asyncModule uses the asynchronous API to obtain the schema model, which seriously affects the API performance.

Minimally reproducible Cube Schema In the following example, by introducing a logger to print information to the console, it is found that the string 'asyncModule getCubeSchema' is printed three times, which means that the asynchronous interface is requested three times.

const {logger} = require("../src/schemaUtils")
asyncModule(async () => {
  const  { securityContext: { systemCode } } =  COMPILE_CONTEXT
  const startTime = Date.now()
  const cubeList = await getCubeSchema({ systemCode })
  logger('asyncModule getCubeSchema:', Date.now() - startTime)
  for(let i = 0; i < cubeList.length; i++ ){
    const { cubeName, ...item } = cubeList[i]
    const dimensions = transformField(item.dimensions)
    const measures = transformField(item.measures)
    cube(cubeName, {
      ...item,
      sql: item.sql,
      dimensions,
      measures
    })
  }
})

Version: [e.g. 1.1.7]

tiger-feng commented 1 day ago

Another question is, in asyncModule, I get the requestId of each request through COMPILE_CONTEXT.requestId. I found that in the same tenant, the requestId obtained after each request is unchanged. I think it should be different every time.