XrmToolBox icon indicating copy to clipboard operation
XrmToolBox copied to clipboard

[Improvement] Forcing a Metadata update

Open BenediktBergmann opened this issue 2 years ago • 13 comments

It would be nice to have the possibility to force a Metadata update without the need of closing the XrmToolBox (XTB).

Example Scenario: I open the XTB and create some queries using Fetch XML Builder (FXB). While XTB is still open I create a new table or a column on an existing table. To be able to use the newly created table/column I have to close the XTB and reopen it so that the Metadata is updated. This costs time especially because I might have to recreate all queries.

I also created the same issue in the FXB Repo https://github.com/rappen/FetchXMLBuilder/issues/897

BenediktBergmann avatar Apr 27 '23 20:04 BenediktBergmann

As the issue opened in the FXB Repo, I think it is more relevant to each tool to add the functionality to refresh the metadata cache since not all of the tools require metadata.

I've seen that functionality in some of the tools.

image

LinnZawWin avatar Apr 27 '23 21:04 LinnZawWin

But it's hard (impossible?) to refresh it for only one tool... The cache is general for the XTB, not for a tool. Right?

rappen avatar Apr 28 '23 06:04 rappen

There is a feature to use a global metadata cache for a connection but not all tools are using this. And if they don't, then they are handling metadata on their own way. So it seems quite impossible to handle all scenario here. I could add a feature to refresh metadata and each tool could register for an event to get notified that cache has been refreshed. But it will still be up to each tool developer to use it or now

MscrmTools avatar Apr 28 '23 15:04 MscrmTools

I like that idea too. Another option is to XTB give a public method to call from tools, and then if called from the tool, it will refresh/reset the metadata cache. Then the tools have to implement the calling it, and ofc to reload the meta after the refresh. I probably like this one more.

rappen avatar Apr 29 '23 14:04 rappen

I've been testing a bit and now committed in FXB #897, and I think it just works, by calling the ConnectionDetail.UpdateMetadataCache(true)

Anyone want to test? If this works fine, then we can probably just close this issue.

rappen avatar Aug 01 '23 18:08 rappen

@rappen How can I get the latest version of FXB which contains that fix? Clone the latest version of FXB from the master repo and build it as a DLL?

LinnZawWin avatar Aug 02 '23 09:08 LinnZawWin

Either build the latest repo, or get the DLL from here: XrmToolBox/Beta

rappen avatar Aug 02 '23 09:08 rappen

@rappen

I just tested and noticed a different behaviour based on the value of "Use cached metadata in XrmToolBox".

If the "Use cached metadata in XrmToolBox" is unchecked, everything is working as expected. The newly created column appears immediately after "Reload all metadata"

But if the "Use cached metadata in XrmToolBox" is checked, the newly created column does not appear in the list when I click the "Reload all metadata" for the first time. (Maybe the cached metadata is being retrieved in the background). I waited for a few minutes (in case there is any background process which updates the metadata once the retrieval is completed) but the new column did not appear. It finally appears when I click "Reload all metadata" for the second time.

In summary, "Reload all metadata" needs to be clicked twice to see the updated metadata if the "Use cached metadata in XrmToolBox" is checked

LinnZawWin avatar Aug 02 '23 10:08 LinnZawWin

I've seen the exact same problem... no idea why. Maybe time to bring in @MarkMpn?

rappen avatar Aug 02 '23 12:08 rappen

UpdateMetadataCache starts a background task to get the latest metadata, so the new metadata won't be visible immediately. The method returns the task details, so you can wait on that task/show a loading notification/... and know when it's complete.

MarkMpn avatar Aug 02 '23 14:08 MarkMpn

It should be done that way... but I'm not sure why/how I made it wrong... Implemented here: https://github.com/rappen/Rappen.XTB.Helper/commit/564a481d42cc1f351c20317638937cd6babf3ccd

So if the user wants to force reloading, it does this before getting the metadata:

if (ForceReload)
{
   worker.ReportProgress(0, "Reloading Metadata...");
   plugin.ConnectionDetail.UpdateMetadataCache(true).ConfigureAwait(false).GetAwaiter();
}     

This is always done in milliseconds. So it isn't really loading all metadata. But it works, if done twice.

I know I ain't best at threads/task/await things...

rappen avatar Aug 02 '23 15:08 rappen

Looks like you’re missing a .GetResult() call at the end of that last line to force it to wait for the task to run.

MarkMpn avatar Aug 02 '23 18:08 MarkMpn

Did I say I'm bad at tasks?

I was looking at other calls like this, and first I had .GetResult() there, but then I know the UpdateMetadataCache is a void, so there won't be anything to return, so I dropped the GetResult. For some reason, that's stupid. It works better now.

New version to test it here: XrmToolBox/Beta

rappen avatar Aug 03 '23 06:08 rappen