Skip to content

Commit ac16b4d

Browse files
committed
use methods rather so the timing of keeping these synced is not a thing
1 parent 0e57da6 commit ac16b4d

File tree

4 files changed

+22
-46
lines changed

4 files changed

+22
-46
lines changed

packages/collection-model/lib/model.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function pickCollectionInfo({
102102
validation,
103103
clustered,
104104
fle2,
105-
is_ghost_namespace,
105+
inferred_from_privileges,
106106
}) {
107107
return {
108108
type,
@@ -113,7 +113,7 @@ function pickCollectionInfo({
113113
validation,
114114
clustered,
115115
fle2,
116-
is_ghost_namespace,
116+
inferred_from_privileges,
117117
};
118118
}
119119

@@ -135,7 +135,7 @@ const CollectionModel = AmpersandModel.extend(debounceActions(['fetch']), {
135135
statusError: { type: 'string', default: null },
136136

137137
// Normalized values from collectionInfo command
138-
is_ghost_namespace: 'boolean',
138+
inferred_from_privileges: 'boolean',
139139
readonly: 'boolean',
140140
clustered: 'boolean',
141141
fle2: 'boolean',
@@ -269,7 +269,7 @@ const CollectionModel = AmpersandModel.extend(debounceActions(['fetch']), {
269269
const shouldFetchDbAndCollStats = getParentByType(
270270
this,
271271
'Instance'
272-
).shouldFetchDbAndCollStats;
272+
).shouldFetchDbAndCollStats();
273273

274274
try {
275275
const newStatus = this.status === 'initial' ? 'fetching' : 'refreshing';
@@ -286,14 +286,14 @@ const CollectionModel = AmpersandModel.extend(debounceActions(['fetch']), {
286286
...collStats,
287287
...(collectionInfo && pickCollectionInfo(collectionInfo)),
288288
});
289-
// If the collection is not unprovisioned `is_ghost_namespace` anymore,
289+
// If the collection is not unprovisioned `inferred_from_privileges` anymore,
290290
// let's update the parent database model to reflect the change.
291291
// This happens when a user tries to insert first document into a
292292
// collection that doesn't exist yet or creates a new collection
293293
// for an unprovisioned database.
294-
if (!this.is_ghost_namespace) {
294+
if (!this.inferred_from_privileges) {
295295
getParentByType(this, 'Database').set({
296-
is_ghost_namespace: false,
296+
inferred_from_privileges: false,
297297
});
298298
}
299299
} catch (err) {
@@ -388,7 +388,7 @@ const CollectionCollection = AmpersandCollection.extend(
388388
const shouldFetchNamespacesFromPrivileges = getParentByType(
389389
this,
390390
'Instance'
391-
).shouldFetchNamespacesFromPrivileges;
391+
).shouldFetchNamespacesFromPrivileges();
392392

393393
if (!databaseName) {
394394
throw new Error(

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ export function createInstancesStore(
290290
const connectedConnectionIds = Array.from(
291291
instancesManager.listMongoDBInstances().keys()
292292
);
293-
294293
for (const connectionId of connectedConnectionIds) {
295294
void refreshDatabases({ connectionId });
296295
}

packages/database-model/lib/model.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const DatabaseModel = AmpersandModel.extend(
105105
statusError: { type: 'string', default: null },
106106
collectionsStatus: { type: 'string', default: 'initial' },
107107
collectionsStatusError: { type: 'string', default: null },
108-
is_ghost_namespace: 'boolean',
108+
inferred_from_privileges: 'boolean',
109109
collection_count: 'number',
110110
document_count: 'number',
111111
storage_size: 'number',
@@ -142,7 +142,7 @@ const DatabaseModel = AmpersandModel.extend(
142142
const shouldFetchDbAndCollStats = getParentByType(
143143
this,
144144
'Instance'
145-
).shouldFetchDbAndCollStats;
145+
).shouldFetchDbAndCollStats();
146146

147147
if (!shouldFetch(this.status, force)) {
148148
return;
@@ -252,7 +252,7 @@ const DatabaseCollection = AmpersandCollection.extend(
252252
}
253253

254254
const shouldFetchNamespacesFromPrivileges =
255-
instanceModel.shouldFetchNamespacesFromPrivileges;
255+
instanceModel.shouldFetchNamespacesFromPrivileges();
256256

257257
const dbs = await dataService.listDatabases({
258258
nameOnly: true,
@@ -262,10 +262,10 @@ const DatabaseCollection = AmpersandCollection.extend(
262262
});
263263

264264
this.set(
265-
dbs.map(({ _id, name, is_ghost_namespace }) => ({
265+
dbs.map(({ _id, name, inferred_from_privileges }) => ({
266266
_id,
267267
name,
268-
is_ghost_namespace,
268+
inferred_from_privileges,
269269
}))
270270
);
271271
},

packages/instance-model/lib/model.js

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -135,33 +135,9 @@ const InstanceModel = AmpersandModel.extend(
135135
isSearchIndexesSupported: 'boolean',
136136
atlasVersion: { type: 'string', default: '' },
137137
csfleMode: { type: 'string', default: 'unavailable' },
138-
shouldFetchDbAndCollStats: { type: 'boolean', default: false },
139-
shouldFetchNamespacesFromPrivileges: { type: 'boolean', default: true },
140138
},
141139
initialize: function ({ preferences, ...props }) {
142-
// Initialize the property directly from preferences
143-
this.set({
144-
shouldFetchDbAndCollStats:
145-
preferences.getPreferences().enableDbAndCollStats,
146-
shouldFetchNamespacesFromPrivileges:
147-
preferences.getPreferences().inferNamespacesFromPrivileges,
148-
});
149-
150-
// Listen to preference changes using the preferences API
151-
this._enableDbAndCollStatsUnsubscribe =
152-
preferences.onPreferenceValueChanged(
153-
'enableDbAndCollStats',
154-
(value) => {
155-
this.set({ shouldFetchDbAndCollStats: value });
156-
}
157-
);
158-
this._inferNamespacesFromPrivilegesUnsubscribe =
159-
preferences.onPreferenceValueChanged(
160-
'inferNamespacesFromPrivileges',
161-
(value) => {
162-
this.set({ shouldFetchNamespacesFromPrivileges: value });
163-
}
164-
);
140+
this.preferences = preferences;
165141

166142
AmpersandModel.prototype.initialize.call(this, props);
167143
},
@@ -420,14 +396,15 @@ const InstanceModel = AmpersandModel.extend(
420396
return coll;
421397
},
422398

399+
shouldFetchDbAndCollStats() {
400+
return this.preferences.getPreferences().enableDbAndCollStats;
401+
},
402+
403+
shouldFetchNamespacesFromPrivileges() {
404+
return this.preferences.getPreferences().inferNamespacesFromPrivileges;
405+
},
406+
423407
removeAllListeners() {
424-
// Clean up preference listeners
425-
if (this._enableDbAndCollStatsUnsubscribe) {
426-
this._enableDbAndCollStatsUnsubscribe();
427-
}
428-
if (this._inferNamespacesFromPrivilegesUnsubscribe) {
429-
this._inferNamespacesFromPrivilegesUnsubscribe();
430-
}
431408
InstanceModel.removeAllListeners(this);
432409
},
433410

0 commit comments

Comments
 (0)