Skip to content

Commit d09fe9e

Browse files
committed
cache loadNative
1 parent 7e56fb4 commit d09fe9e

File tree

1 file changed

+10
-6
lines changed
  • packages/cubejs-backend-native/js

1 file changed

+10
-6
lines changed

packages/cubejs-backend-native/js/index.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,29 @@ export type TransformDataResponseNative = {
118118
result: string
119119
};
120120

121+
let loadedNative: any = null;
122+
121123
export function loadNative() {
124+
if (loadedNative) {
125+
return loadedNative;
126+
}
127+
122128
// Development version
123129
if (fs.existsSync(path.join(__dirname, '/../../index.node'))) {
124-
return require(path.join(__dirname, '/../../index.node'));
130+
loadedNative = require(path.join(__dirname, '/../../index.node'));
131+
return loadedNative;
125132
}
126133

127134
if (fs.existsSync(path.join(__dirname, '/../../native/index.node'))) {
128-
return require(path.join(__dirname, '/../../native/index.node'));
135+
loadedNative = require(path.join(__dirname, '/../../native/index.node'));
136+
return loadedNative;
129137
}
130138

131139
throw new Error(
132140
`Unable to load @cubejs-backend/native, probably your system (${process.arch}-${process.platform}) with Node.js ${process.version} is not supported.`,
133141
);
134142
}
135143

136-
export function isSupported(): boolean {
137-
return fs.existsSync(path.join(__dirname, '/../../index.node')) || fs.existsSync(path.join(__dirname, '/../../native/index.node'));
138-
}
139-
140144
function wrapNativeFunctionWithChannelCallback(
141145
fn: (extra: any) => unknown | Promise<unknown>,
142146
) {

0 commit comments

Comments
 (0)