Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions packages/compass-app-stores/src/stores/instance-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,13 @@ export function createInstancesStore(
> = {},
{ connectionId }: { connectionId?: string } = {}
) => {
let isFirstRun: boolean | undefined;

try {
if (!connectionId) {
throw new Error('No connectionId provided');
}
const instance =
instancesManager.getMongoDBInstanceForConnection(connectionId);
const dataService = connections.getDataServiceForConnection(connectionId);
isFirstRun = instance.status === 'initial';
await instance.refresh({
dataService,
...refreshOptions,
Expand All @@ -123,7 +120,7 @@ export function createInstancesStore(
{
message: (err as Error).message,
connectionId: connectionId,
isFirstRun,
isFirstRun: refreshOptions.firstRun,
}
);
// The `instance.refresh` method is catching all expected errors: we treat
Expand All @@ -137,7 +134,7 @@ export function createInstancesStore(
// place for the user to see the error. This is a very rare case, but we
// don't want to leave the user without any indication that something went
// wrong and so we show an toast with the error message
if (isFirstRun) {
if (refreshOptions.firstRun) {
const { name, message } = err as Error;
openToast('instance-refresh-failed', {
title: 'Failed to retrieve server info',
Expand Down Expand Up @@ -359,6 +356,7 @@ export function createInstancesStore(
{
fetchDatabases: true,
fetchDbStats: true,
firstRun: true,
},
{
connectionId: instanceConnectionId,
Expand Down
11 changes: 11 additions & 0 deletions packages/compass-e2e-tests/tests/logging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,17 @@ describe('Logging and Telemetry integration', function () {
)}`
);
});

it('only calls instance info for a connection once', function () {
expect(
logs.filter((v) => {
return (
v.c === 'COMPASS-DATA-SERVICE' &&
v.msg.startsWith('Running instance')
);
})
).to.have.lengthOf(1);
});
});
});

Expand Down
1 change: 1 addition & 0 deletions packages/instance-model/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ declare class MongoDBInstance extends MongoDBInstanceProps {
fetchCollections?: boolean;
fetchCollInfo?: boolean;
fetchCollStats?: boolean;
firstRun?: boolean;
}): Promise<void>;
getNamespace(opts: {
dataService: Pick<DataService, 'instance' | 'getCurrentTopologyType'>;
Expand Down
11 changes: 10 additions & 1 deletion packages/instance-model/lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ const InstanceModel = AmpersandModel.extend(
fetchDbStats = false,
fetchCollections = false,
fetchCollStats = false,
firstRun = false,
}) {
this.set({
refreshingStatus:
Expand All @@ -331,7 +332,15 @@ const InstanceModel = AmpersandModel.extend(

try {
// First fetch instance info ...
await this.fetch({ dataService, force: true });
await this.fetch({
dataService,
// NB: We're optimizing the first run case by passing the instance
// info directly to the instance when constructing the class. In all
// the other cases we will force refresh it, but if this is a first
// run, we won't force this (and it will short circuit in the fetch
// method)
force: !firstRun,
});

// ... and databases list. These are the essentials that we need to make
// Compass somewhat usable
Expand Down
Loading