Skip to content

Commit d2f58de

Browse files
authored
fix(app-stores): do not force instance fetching on first run COMPASS-9549 (#7130)
fix(app-stores): do not force instance fetching on first run
1 parent e3a3ffd commit d2f58de

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

packages/compass-app-stores/src/stores/instance-store.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,13 @@ export function createInstancesStore(
101101
> = {},
102102
{ connectionId }: { connectionId?: string } = {}
103103
) => {
104-
let isFirstRun: boolean | undefined;
105-
106104
try {
107105
if (!connectionId) {
108106
throw new Error('No connectionId provided');
109107
}
110108
const instance =
111109
instancesManager.getMongoDBInstanceForConnection(connectionId);
112110
const dataService = connections.getDataServiceForConnection(connectionId);
113-
isFirstRun = instance.status === 'initial';
114111
await instance.refresh({
115112
dataService,
116113
...refreshOptions,
@@ -123,7 +120,7 @@ export function createInstancesStore(
123120
{
124121
message: (err as Error).message,
125122
connectionId: connectionId,
126-
isFirstRun,
123+
isFirstRun: refreshOptions.firstRun,
127124
}
128125
);
129126
// The `instance.refresh` method is catching all expected errors: we treat
@@ -137,7 +134,7 @@ export function createInstancesStore(
137134
// place for the user to see the error. This is a very rare case, but we
138135
// don't want to leave the user without any indication that something went
139136
// wrong and so we show an toast with the error message
140-
if (isFirstRun) {
137+
if (refreshOptions.firstRun) {
141138
const { name, message } = err as Error;
142139
openToast('instance-refresh-failed', {
143140
title: 'Failed to retrieve server info',
@@ -359,6 +356,7 @@ export function createInstancesStore(
359356
{
360357
fetchDatabases: true,
361358
fetchDbStats: true,
359+
firstRun: true,
362360
},
363361
{
364362
connectionId: instanceConnectionId,

packages/compass-e2e-tests/tests/logging.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,17 @@ describe('Logging and Telemetry integration', function () {
417417
)}`
418418
);
419419
});
420+
421+
it('only calls instance info for a connection once', function () {
422+
expect(
423+
logs.filter((v) => {
424+
return (
425+
v.c === 'COMPASS-DATA-SERVICE' &&
426+
v.msg.startsWith('Running instance')
427+
);
428+
})
429+
).to.have.lengthOf(1);
430+
});
420431
});
421432
});
422433

packages/instance-model/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ declare class MongoDBInstance extends MongoDBInstanceProps {
123123
fetchCollections?: boolean;
124124
fetchCollInfo?: boolean;
125125
fetchCollStats?: boolean;
126+
firstRun?: boolean;
126127
}): Promise<void>;
127128
getNamespace(opts: {
128129
dataService: Pick<DataService, 'instance' | 'getCurrentTopologyType'>;

packages/instance-model/lib/model.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ const InstanceModel = AmpersandModel.extend(
323323
fetchDbStats = false,
324324
fetchCollections = false,
325325
fetchCollStats = false,
326+
firstRun = false,
326327
}) {
327328
this.set({
328329
refreshingStatus:
@@ -331,7 +332,15 @@ const InstanceModel = AmpersandModel.extend(
331332

332333
try {
333334
// First fetch instance info ...
334-
await this.fetch({ dataService, force: true });
335+
await this.fetch({
336+
dataService,
337+
// NB: We're optimizing the first run case by passing the instance
338+
// info directly to the instance when constructing the class. In all
339+
// the other cases we will force refresh it, but if this is a first
340+
// run, we won't force this (and it will short circuit in the fetch
341+
// method)
342+
force: !firstRun,
343+
});
335344

336345
// ... and databases list. These are the essentials that we need to make
337346
// Compass somewhat usable

0 commit comments

Comments
 (0)