Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improvement] Forcing a Metadata update #1256

Open
BenediktBergmann opened this issue Apr 27, 2023 · 13 comments
Open

[Improvement] Forcing a Metadata update #1256

BenediktBergmann opened this issue Apr 27, 2023 · 13 comments

Comments

@BenediktBergmann
Copy link

BenediktBergmann commented Apr 27, 2023

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
rappen/FetchXMLBuilder#897

@LinnZawWin
Copy link

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

@rappen
Copy link
Collaborator

rappen commented Apr 28, 2023

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

@MscrmTools
Copy link
Owner

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

@rappen
Copy link
Collaborator

rappen commented Apr 29, 2023

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
Copy link
Collaborator

rappen commented Aug 1, 2023

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.

@LinnZawWin
Copy link

@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?

@rappen
Copy link
Collaborator

rappen commented Aug 2, 2023

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

@LinnZawWin
Copy link

@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

@rappen
Copy link
Collaborator

rappen commented Aug 2, 2023

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

@MarkMpn
Copy link
Contributor

MarkMpn commented Aug 2, 2023

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.

@rappen
Copy link
Collaborator

rappen commented Aug 2, 2023

It should be done that way... but I'm not sure why/how I made it wrong...
Implemented here: rappen/Rappen.XTB.Helper@564a481

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...

@MarkMpn
Copy link
Contributor

MarkMpn commented Aug 2, 2023

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.

@rappen
Copy link
Collaborator

rappen commented Aug 3, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants