Problem
When browsing databases in the tree view, there is no indication of how many collections a database contains until you expand it. Users must click to expand every database just to understand its contents.
In contrast, CollectionItem already shows a document count in its description (e.g., 5.2k docs) using a lazy loading pattern. DatabaseItem should follow the same approach.
Current:
▼ my-cluster
▶ my-database <-- no count
Expected:
▼ my-cluster
▶ my-database (12 collections)
Expected Behavior
After a DatabaseItem is rendered, the extension should asynchronously fetch the collection count and display it as the tree item's description. The count should load in the background without blocking tree expansion.
Development Hints
Since this is a good first issue, here are some hints on where to start:
Pattern to follow: src/tree/documentdb/CollectionItem.ts
CollectionItem already implements a lazy loading pattern for document count. The approach uses:
- A cached count field (
documentCount) with three states: undefined (not loaded), number (loaded), null (failed)
- A boolean guard (
isLoadingCount) to prevent duplicate fetches
- A public
loadDocumentCount() method called from the parent's getChildren()
- A private
fetchAndUpdateCount() that retrieves the count and calls ext.state.notifyChildrenChanged(this.id) to refresh the tree item
You should replicate this pattern in DatabaseItem:
- Add
collectionCount, isLoadingCount fields and a loadCollectionCount() / fetchAndUpdateCount() method pair
- In
fetchAndUpdateCount(), use ClustersClient.listCollections() to get the collection list and take its .length
- In
getTreeItem(), set description based on the loaded count (e.g., "12 collections" or "1 collection")
- In
DatabaseItem's parent (ClusterItemBase or similar), call databaseItem.loadCollectionCount() after creating each DatabaseItem in getChildren()
Copying the lazy loading code from CollectionItem is fine for this issue. We can create a follow-up refactoring issue to deduplicate the pattern later. The focus here is the feature, not code reuse.
Key API: ClustersClient.listCollections(databaseName) returns a CollectionItemModel[]. Use its .length for the count.
Files to Modify
| File |
Change |
src/tree/documentdb/DatabaseItem.ts |
Add lazy loading fields, methods, and description in getTreeItem() |
Parent tree item that creates DatabaseItem instances |
Call loadCollectionCount() after creating each DatabaseItem |
Acceptance Criteria
Problem
When browsing databases in the tree view, there is no indication of how many collections a database contains until you expand it. Users must click to expand every database just to understand its contents.
In contrast,
CollectionItemalready shows a document count in its description (e.g.,5.2k docs) using a lazy loading pattern.DatabaseItemshould follow the same approach.Expected Behavior
After a
DatabaseItemis rendered, the extension should asynchronously fetch the collection count and display it as the tree item'sdescription. The count should load in the background without blocking tree expansion.Development Hints
Since this is a
good first issue, here are some hints on where to start:Pattern to follow:
src/tree/documentdb/CollectionItem.tsCollectionItemalready implements a lazy loading pattern for document count. The approach uses:documentCount) with three states:undefined(not loaded),number(loaded),null(failed)isLoadingCount) to prevent duplicate fetchesloadDocumentCount()method called from the parent'sgetChildren()fetchAndUpdateCount()that retrieves the count and callsext.state.notifyChildrenChanged(this.id)to refresh the tree itemYou should replicate this pattern in
DatabaseItem:collectionCount,isLoadingCountfields and aloadCollectionCount()/fetchAndUpdateCount()method pairfetchAndUpdateCount(), useClustersClient.listCollections()to get the collection list and take its.lengthgetTreeItem(), setdescriptionbased on the loaded count (e.g.,"12 collections"or"1 collection")DatabaseItem's parent (ClusterItemBaseor similar), calldatabaseItem.loadCollectionCount()after creating eachDatabaseItemingetChildren()Copying the lazy loading code from
CollectionItemis fine for this issue. We can create a follow-up refactoring issue to deduplicate the pattern later. The focus here is the feature, not code reuse.Key API:
ClustersClient.listCollections(databaseName)returns aCollectionItemModel[]. Use its.lengthfor the count.Files to Modify
src/tree/documentdb/DatabaseItem.tsdescriptioningetTreeItem()DatabaseIteminstancesloadCollectionCount()after creating eachDatabaseItemAcceptance Criteria
DatabaseItemshows collection count as description (e.g.,12 collectionsor1 collection)0 collections