Skip to content

Commit f787007

Browse files
authored
fix(storage): import path jit (#4700)
1 parent f0262de commit f787007

File tree

9 files changed

+21
-24
lines changed

9 files changed

+21
-24
lines changed

packages/compass-connections/src/components/connections.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ const { log, mongoLogId } = createLoggerAndTelemetry(
2929
'mongodb-compass:connections:connections'
3030
);
3131

32-
const { basepath } = getStoragePaths() ?? {};
33-
3432
type ConnectFn = typeof connect;
3533

3634
export type { ConnectFn };
@@ -63,7 +61,7 @@ function Connections({
6361
appRegistry,
6462
onConnected,
6563
isConnected,
66-
connectionStorage = new ConnectionStorage(basepath),
64+
connectionStorage = new ConnectionStorage(getStoragePaths()?.basepath),
6765
appName,
6866
getAutoConnectInfo,
6967
connectFn = connect,
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import path from 'path';
22
import { getStoragePaths } from '@mongodb-js/compass-utils';
3-
const { appName, basepath } = getStoragePaths() || {};
43

54
export function getUserDataFolderPath() {
5+
const { appName, basepath } = getStoragePaths() || {};
66
if (appName === undefined || basepath === undefined) {
77
throw new Error('cannot access user data folder path');
88
}
9-
9+
// Todo: https://jira.mongodb.org/browse/COMPASS-7080
10+
// We should directly call getStoragePaths wherever this function is called.
11+
// It creates nested folder with appName as folder name.
1012
return path.join(basepath, appName);
1113
}

packages/compass-preferences-model/src/setup-preferences.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type { ParsedGlobalPreferencesResult } from './global-config';
1111

1212
import { getStoragePaths } from '@mongodb-js/compass-utils';
1313
import type { PreferencesAccess } from '.';
14-
const { basepath } = getStoragePaths() || {};
1514

1615
let preferencesSingleton: Preferences | undefined;
1716

@@ -23,7 +22,7 @@ export async function setupPreferences(
2322
}
2423

2524
const preferences = (preferencesSingleton = new Preferences(
26-
basepath,
25+
getStoragePaths()?.basepath,
2726
globalPreferences
2827
));
2928

packages/compass-preferences-model/src/utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ import type { ParsedGlobalPreferencesResult } from '.';
33
import { setupPreferences } from './setup-preferences';
44
import { UserStorage } from './storage';
55
import { getStoragePaths } from '@mongodb-js/compass-utils';
6-
const { basepath } = getStoragePaths() || {};
7-
8-
const userStorage = new UserStorage(basepath);
96

107
export async function setupPreferencesAndUser(
118
globalPreferences: ParsedGlobalPreferencesResult
129
): Promise<void> {
1310
await setupPreferences(globalPreferences);
11+
const userStorage = new UserStorage(getStoragePaths()?.basepath);
1412
const user = await userStorage.getOrCreate(getActiveUserId());
1513
// update user id (telemetryAnonymousId) in preferences if new user was created.
1614
await preferences.savePreferences({ telemetryAnonymousId: user.id });
@@ -25,6 +23,7 @@ function getActiveUserId() {
2523
}
2624

2725
export async function getActiveUser() {
26+
const userStorage = new UserStorage(getStoragePaths()?.basepath);
2827
return userStorage.getUser(getActiveUserId());
2928
}
3029

packages/compass-query-bar/src/stores/query-bar-store.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import {
2727
import { getStoragePaths } from '@mongodb-js/compass-utils';
2828
import { AtlasService } from '@mongodb-js/atlas-service/renderer';
2929

30-
const { basepath } = getStoragePaths() || {};
31-
3230
// Partial of DataService that mms shares with Compass.
3331
type QueryBarDataService = Pick<DataService, 'sample' | 'getConnectionString'>;
3432

@@ -83,11 +81,11 @@ function createStore(options: Partial<QueryBarStoreOptions> = {}) {
8381
dataProvider,
8482
atlasService = new AtlasService(),
8583
recentQueryStorage = new RecentQueryStorage(
86-
options.basepath ?? basepath,
84+
options.basepath ?? getStoragePaths()?.basepath,
8785
namespace
8886
),
8987
favoriteQueryStorage = new FavoriteQueryStorage(
90-
options.basepath ?? basepath,
88+
options.basepath ?? getStoragePaths()?.basepath,
9189
namespace
9290
),
9391
} = options;

packages/compass-saved-aggregations-queries/src/stores/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import { FavoriteQueryStorage } from '@mongodb-js/compass-query-bar';
1717
import { PipelineStorage } from '@mongodb-js/compass-aggregations';
1818
import { getStoragePaths } from '@mongodb-js/compass-utils';
1919

20-
const { basepath } = getStoragePaths() ?? {};
2120
// Exporting so that they can be stubed/spied in tests
22-
export const queryStorage = new FavoriteQueryStorage(basepath);
21+
export const queryStorage = new FavoriteQueryStorage(
22+
getStoragePaths()?.basepath
23+
);
2324
export const pipelineStorage = new PipelineStorage();
2425

2526
const _store = createStore(
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
const path = require('path');
22
const { getStoragePaths } = require('@mongodb-js/compass-utils');
3-
const { appName, basepath } = getStoragePaths() || {};
43

54
export function getUserDataFilePath(filename) {
5+
const { appName, basepath } = getStoragePaths() || {};
66
if (appName === undefined || basepath === undefined) return;
77

8+
// Todo: https://jira.mongodb.org/browse/COMPASS-7080
9+
// We should directly call getStoragePaths wherever this function is called.
10+
// It creates nested folder with appName as folder name.
811
return path.join(basepath, appName, filename);
912
}

packages/compass-sidebar/src/modules/connection-info.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { getStoragePaths } from '@mongodb-js/compass-utils';
44

55
const { debug } = createLoggerAndTelemetry('COMPASS-SIDEBAR');
66

7-
const { basepath } = getStoragePaths() ?? {};
8-
97
/**
108
* Change connection action name.
119
*/
@@ -25,7 +23,7 @@ export const INITIAL_STATE = {
2523
connectionString: 'mongodb://localhost:27017',
2624
},
2725
},
28-
connectionStorage: new ConnectionStorage(basepath),
26+
connectionStorage: new ConnectionStorage(getStoragePaths()?.basepath),
2927
};
3028

3129
async function saveConnectionInfo(connectionInfo, connectionStorage) {

packages/connection-storage/src/import-export-connection.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { Decrypter, Encrypter } from './encrypt';
88
import createLoggerAndTelemetry from '@mongodb-js/compass-logging';
99
import { getStoragePaths } from '@mongodb-js/compass-utils';
1010

11-
const { basepath } = getStoragePaths() ?? {};
12-
1311
const { log, mongoLogId, track } = createLoggerAndTelemetry(
1412
'COMPASS-CONNECTION-IMPORT-EXPORT'
1513
);
@@ -40,7 +38,8 @@ export async function exportConnections(
4038
options: ExportConnectionOptions = {}
4139
): Promise<string> {
4240
const {
43-
loadConnections = async () => new ConnectionStorage(basepath).loadAll(),
41+
loadConnections = async () =>
42+
new ConnectionStorage(getStoragePaths()?.basepath).loadAll(),
4443
filter = (info) => info.favorite?.name,
4544
passphrase = '',
4645
removeSecrets = false,
@@ -109,7 +108,7 @@ class CompassImportError extends Error {
109108
async function saveConnectionsToDefaultStorage(
110109
connections: ConnectionInfo[]
111110
): Promise<void> {
112-
const storage = new ConnectionStorage(basepath);
111+
const storage = new ConnectionStorage(getStoragePaths()?.basepath);
113112
await Promise.all(connections.map((conn) => storage.save(conn)));
114113
}
115114

0 commit comments

Comments
 (0)