Skip to content

Commit f24603a

Browse files
authored
fix(data-service): ignore errors when fetching collStats in adf; always fetch collInfo COMPASS-7307 (#4963)
* fix(data-service): ignore collStats errors for adf * fix(instance-model): fix collInfo when expanding database in the sidenav
1 parent a3f3579 commit f24603a

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

packages/collection-model/lib/model.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ const CollectionCollection = AmpersandCollection.extend(
334334
* @param {{ dataService: import('mongodb-data-service').DataService }} dataService
335335
* @returns {Promise<void>}
336336
*/
337-
async fetch({ dataService, fetchInfo = true }) {
337+
async fetch({ dataService }) {
338338
const databaseName = getParentByType(this, 'Database')?.getId();
339339

340340
if (!databaseName) {
@@ -354,7 +354,11 @@ const CollectionCollection = AmpersandCollection.extend(
354354
const collections = await dataService.listCollections(
355355
databaseName,
356356
{},
357-
{ nameOnly: !fetchInfo, privileges: instanceModel.auth.privileges }
357+
{
358+
// Always fetch collections with info
359+
nameOnly: false,
360+
privileges: instanceModel.auth.privileges,
361+
}
358362
);
359363

360364
this.set(
@@ -370,7 +374,7 @@ const CollectionCollection = AmpersandCollection.extend(
370374
return {
371375
_id,
372376
type,
373-
...(fetchInfo && pickCollectionInfo(rest)),
377+
...pickCollectionInfo(rest),
374378
};
375379
})
376380
);

packages/data-service/src/data-service.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,10 +1006,16 @@ class DataServiceImpl extends WithLogContext implements DataService {
10061006
collStats[0]
10071007
);
10081008
} catch (error) {
1009-
if (!(error as Error).message.includes('is a view, not a collection')) {
1010-
throw error;
1009+
const message = (error as Error).message;
1010+
// We ignore errors for fetching collStats when requesting on an
1011+
// unsupported collection type: either a view or a ADF
1012+
if (
1013+
message.includes('not valid for Data Lake') ||
1014+
message.includes('is a view, not a collection')
1015+
) {
1016+
return this._buildCollectionStats(databaseName, collectionName, {});
10111017
}
1012-
return this._buildCollectionStats(databaseName, collectionName, {});
1018+
throw error;
10131019
}
10141020
}
10151021

packages/database-model/lib/model.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ const DatabaseModel = AmpersandModel.extend(
153153
* @param {{ dataService: import('mongodb-data-service').DataService }} dataService
154154
* @returns {Promise<void>}
155155
*/
156-
async fetchCollections({ dataService, fetchInfo = false, force = false }) {
156+
async fetchCollections({ dataService, force = false }) {
157157
if (!shouldFetch(this.collectionsStatus, force)) {
158158
return;
159159
}
@@ -162,7 +162,7 @@ const DatabaseModel = AmpersandModel.extend(
162162
const newStatus =
163163
this.collectionsStatus === 'initial' ? 'fetching' : 'refreshing';
164164
this.set({ collectionsStatus: newStatus });
165-
await this.collections.fetch({ dataService, fetchInfo, force });
165+
await this.collections.fetch({ dataService, force });
166166
this.set({ collectionsStatus: 'ready', collectionsStatusError: null });
167167
} catch (err) {
168168
this.set({
@@ -180,7 +180,6 @@ const DatabaseModel = AmpersandModel.extend(
180180
}) {
181181
await this.fetchCollections({
182182
dataService,
183-
fetchInfo: !nameOnly,
184183
force,
185184
});
186185

@@ -192,7 +191,12 @@ const DatabaseModel = AmpersandModel.extend(
192191
// the allSettled call here
193192
await Promise.allSettled(
194193
this.collections.map((coll) => {
195-
return coll.fetch({ dataService, fetchInfo: false, force });
194+
return coll.fetch({
195+
dataService,
196+
// We already fetched it with fetchCollections
197+
fetchInfo: false,
198+
force
199+
});
196200
})
197201
);
198202
},

packages/instance-model/lib/model.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ const InstanceModel = AmpersandModel.extend(
285285
fetchDatabases = false,
286286
fetchDbStats = false,
287287
fetchCollections = false,
288-
fetchCollInfo = false,
289288
fetchCollStats = false,
290289
}) {
291290
this.set({
@@ -310,7 +309,6 @@ const InstanceModel = AmpersandModel.extend(
310309
if (shouldRefresh(db.collectionsStatus, fetchCollections)) {
311310
return db.fetchCollections({
312311
dataService,
313-
fetchInfo: fetchCollInfo,
314312
force: true,
315313
});
316314
}
@@ -330,10 +328,8 @@ const InstanceModel = AmpersandModel.extend(
330328
if (shouldRefresh(coll.status, fetchCollStats)) {
331329
return coll.fetch({
332330
dataService,
333-
// When fetchCollInfo is true, we skip fetching collection
334-
// info returned by listCollections command as we already
335-
// did that in the previous step
336-
fetchInfo: !fetchCollInfo,
331+
// We already fetched it with fetchCollections
332+
fetchInfo: false,
337333
force: true,
338334
});
339335
}

0 commit comments

Comments
 (0)