microsoft / vscode-azureresourcegroups

VS Code extension for managing Azure resources.
https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azureresourcegroups
MIT License
52 stars 28 forks source link

Only keep one object per id cached #641

Closed alexweininger closed 1 year ago

alexweininger commented 1 year ago

Fixes #640, and a bunch of others including:

Background

This following line was added in https://github.com/microsoft/vscode-azureresourcegroups/pull/510 as a band aid solution to try and fix issues where the item returned by the picker was not reference equal to the same item in the tree view. This made it so calling refresh with the item didn't refresh on the tree among other things. https://github.com/microsoft/vscode-azureresourcegroups/blob/11e06179ad12c30fb01259bbe8bfc0a87304c8eb/src/api/compatibility/pickAppResource.ts#L19

The fix in #510 only worked sometimes, as seen by the numerous bugs reported by CTI surrounding things not refreshing on the tree when commands are invoked via command palette. It turns out this is because multiple items were being added to the cache with the same id. We were just returning the first one we found with a matching id when iterating through the cached items.

Solution

The solution I implemented makes it so we only ever have one object in memory for each id. Before creating a new object, we check if we have an object in the cache with that id.

In psuedocode:

if (cache.getItemForId(id)) {
    return cache.getItemForId(id)
} else {
    return createItem(id);
}

I've taken extra time on this PR to do a lot of manual testing with the client extensions to make sure this functionality works. I will have CTI do test passes on the clients as well.

alexweininger commented 1 year ago

I've made changes to this PR so that the wrapped branch items are updated underneath the cached resource group items.