SetPersistDataAsync Causes Two Calls to DataManager

Hi Team Syncfusion,

Please see this repository:

https://github.com/Mike-E-angelo/Stash/tree/master/Syncfusion.Grid.State

After running it and loading Index.razor, you will see this line get hit twice:

https://github.com/Mike-E-angelo/Stash/blob/master/Syncfusion.Grid.State/Pages/Index.razor#L48

Expected: This line should only be called once.

Commenting out these lines makes it work as expected:

https://github.com/Mike-E-angelo/Stash/blob/master/Syncfusion.Grid.State/Pages/Index.razor#L80-L87

So it would seem that `SetPersistDataAsync` invokes two calls to the DataAdaptor.Read method, when only one is expected.

Please let me know if there is any further information I can provide to further assist and diagnose this issue.


58 Replies 1 reply marked as answer

SP Sarveswaran Palani Syncfusion Team September 13, 2022 02:31 AM UTC

Hi Mike,


Greetings from Syncfusion support.


We have analyzed your query and check the provided sample. We would like to inform that SetPersistanceDataAsync method is used to load the previously saved state of grid. So that, read method get hit twice in the provided sample. This is the default behaviour of this method. Please refer the attached reference link.


Reference: https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_SetPersistDataAsync_System_String_


Kindly get back to us if you have any further queries.


Regards,

Sarveswaran PK





MI Mike-E September 13, 2022 07:02 AM UTC

Thank you for the reply @Sarveswaran.  I understand that i is currently default behavior, or at least the behavior as currently experienced.  However, this seems like it is a bug as you would be able to note on your side that the data has already been retrieved and does not need to be retrieved a second time on page load.

Because of this issue, two calls are being made to my database whenever I load your control on my pages, of which there are about 100 of them throughout my application.  This seems a bit wasteful and unnecessary.

I appreciate any consideration towards addressing this issue on your side.



SP Sarveswaran Palani Syncfusion Team September 14, 2022 08:42 PM UTC

Hi Mike,


Greetings from Syncfusion support.


Thanks for taking time to informing us and we’ll check with concern dev team and update you the further details.


Until then we appreciate your response.


Kindly get back to us if you have any further queries.


Regards,

Sarveswaran PK




MI Mike-E November 3, 2022 08:48 AM UTC

Hi @Sarveswaran I wanted to check in with this to see when this can be addressed.  I have disabled the state on my grid controls but customers are noticing this and are making comments.  So now I am in between two difficult propositions of having no state or state with two calls to the database with each call.

Thank you for any update you can provide.



MI Mike-E November 8, 2022 08:41 AM UTC

Hello any update would p



SP Sarveswaran Palani Syncfusion Team November 9, 2022 03:18 AM UTC

Hi Mike,


Sorry for the delay,


Based on your update, we'd like to inform you that in order to persist the filter settings, sorting and group-by methods, it is necessary to recall the Read method again. This is the default behavior. But from your sample, you only update the column properties, so you need not to data process again. Please let us know, If you’re not using filtering, sorting, grouping in your project, and you need only update the column. We’ll consider this as bug and implement in upcoming patch release.


Regards,

Sarvesh



MI Mike-E November 9, 2022 08:04 AM UTC

Hi @Sarveswaran,


Thank you for your update.  I am indeed using sorting/filter as that is how a grid is typically used.  Based on my investigation, the query to the database is exactly the same twice.  As such, it would seem that the first call would be utilized/stored/cached on the client so that two calls to the database are not necessary.

Please do let me know if I have something misunderstood.



MI Mike-E November 15, 2022 08:49 AM UTC

Hi @Saeveswaran I would like to get this attended to sooner rather than later as it is a performance issue with my application.  Thank you for any update/effort you can provide.



MI Mike-E November 18, 2022 01:03 PM UTC

Hi Sarveswaran I wanted to check in with this issue as I have not heard back since November 8.  Thank you for any update you can provide.



SP Sarveswaran Palani Syncfusion Team November 21, 2022 04:41 AM UTC

Hi Mike,

Sorry for the delay and inconvenience caused.


Currently we're checking your query with our dev team on high priority at our end, we'll update the proper solution within tomorrow.

Until then we appreciate your patience.

Regards,
Sarveswaran PK


SP Sarveswaran Palani Syncfusion Team November 24, 2022 04:43 AM UTC

Hi Mike,

Sorry for the delay.


It is necessary to recall the Read method once more in order to maintain the filter settings, sorting, and grouping methods, as we previously explained. If some users use an external button to call the SetPersistDataAsync method, the Read method must be called once to read the DataProcess. In your scenario, rendering SetPersistDataAsync method within OnAfterRenderAsync cycle leads to calls the read method twice. This is the default behavior in nature.


Regards,
Sarvesh




MI Mike-E November 25, 2022 11:21 AM UTC

Thank you for the update @Sarvesh.  In this case this is not a button being pressed, but basic grid initialization.  Is there no way to defer the Read call during this scenario so that only one call is made to the database?

In some cases, I have more than one grid on a page so this is a compounding problem for my system.

Ideally, it would be valuable to have some way to signal to the grid that "hey I am going to call `SetPersistDataAsync` so please hold off on calling read during initialization until this is done."

That way this results in only one call during initialization.

Thank you for any consideration you can provide towards this. 



MI Mike-E December 5, 2022 06:47 PM UTC

Hi Sarvesh I wanted to check in with this as I have not heard back and this is a priority for my application.  The goal here is to only have ReadData called once during initialization.  Thank you for any guidance/consideration you can provide.



MI Mike-E December 8, 2022 09:04 PM UTC

Hi Sarvesh thank you for any update you can provide.



SP Sarveswaran Palani Syncfusion Team December 9, 2022 04:32 AM UTC

Hi Mike,

Sorry for the late response from our end.


As we explained earlier, if we persist the filter settings, sorting and group-by methods, it is necessary to recall the Read method again. If some users use an external button to call the SetPersistDataAsync method, the Read method must be called once to read the DataProcess. This is the purpose of us to call the ReadMethod while using SetPersistDataAsync method. In your scenario, rendering SetPersistDataAsync method within OnAfterRenderAsync cycle leads to calls the read method twice. But from your sample, you only update the column properties, so you need not to data process again. If yes, we’ll consider this as bug and include in any of our upcoming patch release.

Regards,
Sarvesh



MI Mike-E December 9, 2022 10:52 PM UTC

Thank you for your reply @Sarvesh. Do pardon the confusion here but it's not just ReadData that is being called, but the Sql Server that is being called twice. This is occurring on every page that has an SfGrid control on it. In some cases, I have 3 grids so that is 6 calls to my Azure Sql Database which consumes DTU and ultimately costs me money. I hope that further explains my concern here.


In the sample I provided, you should see that SQL commands sent out to the SQL server are being generated and executed twice, and the expectation is that they only get generated and executed once.


Thank you for any further assistance/consideration you can provide toward improving this scenario.



MS Monisha Saravanan Syncfusion Team December 12, 2022 02:21 PM UTC

Hi Mike,


Query: “it's not just ReadData that is being called, but the Sql Server that is being called twice.”


We suspect that the SQL server is called twice. Because inside the Read method we have fetched the data from the SQL server. So if we prevent the ReadAsync call then the call to the SQL will be prevented and kindly confirm us whether you are mentioning the same issue.


public override object Read(DataManagerRequest dm, string key = null)

        {

            Debug.WriteLine($"{nameof(CustomAdaptor)}.{nameof(Read)}");

            IEnumerable<Order> DataSource = db.GetAllOrders();

          


Please get back to us if we misunderstood your query or if you have further queries.


Regards,

Monisha



MI Mike-E December 13, 2022 09:20 AM UTC

Hi Monisha,


Pardon the false alarm here. I did try to unmark my previous answer as the solution, but there was no way to do so, so I deleted it.


I did look into working around this, but the problem is this:


  1. Please open the solution here:
    https://github.com/Mike-E-angelo/Stash/tree/master/Syncfusion.Grid.State
  2. Put a breakpoint on line 48, line 84, and line  85
  3. Run solution. Breakpoints 84, 48, and 85 are called in that order. This is expected. ✅
  4. Continue to run the application and line 48 is called again. This is not expected ❌

As a result, this makes 2 calls to the database. Is there a way to avoid this?


Please let me know if that better explains the problem. Thank you for any further assistance you can provide.



MI Mike-E December 20, 2022 09:33 AM UTC

Hi Monisha & Team, I wanted to check in on this issue.  Please let me know if there is any further information I can provide to help diagnose and/or explain the issue.

Again, when manually loading data via `SetPersistDataAsync` another subsequent call is made after this that is not expected/desired, leading to two calls to the database rather than one.

Thank you for any consideration towards addressing this.



SP Sarveswaran Palani Syncfusion Team December 21, 2022 02:11 PM UTC

Hi Mike,


We have validated and considered your query as a bug and logged the defect report “Prevent SetPersistDataAsync method to call Read method twice” for the same. Thank you for taking the time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle) and will include the fix in any of our upcoming patch release.


You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link. 


https://www.syncfusion.com/feedback/39939/prevent-setpersistdataasync-method-to-call-read-method-twice


Disclaimer: “Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization”


Until then we appreciate your patience.


Regards,

Sarveswaran PK



MI Mike-E December 22, 2022 09:04 PM UTC

Woohoo!  Great, thank you so very much Sarveswaran and team!  Happy Holidays to everyone out there 🎅⛄🎄



SZ Szoke replied to Sarveswaran Palani January 28, 2023 09:39 PM UTC

Huh, that would be great if you could find a solution!



MI Mike-E January 29, 2023 10:23 AM UTC

Hi @Sarveswaran any update here please?



SP Sarveswaran Palani Syncfusion Team February 1, 2023 02:22 PM UTC

Hi Mike-E ,

We are glad to announce that our Essential Studio 2022 patch Release v20.4.0.48 is rolled out and is available for download under the following link and we have included fix for the issue   Prevent SetPersistDataAsync method to call Read method twicein our patch release (20.4.0.48).


NuGet : https://www.nuget.org/packages/Syncfusion.Blazor.Grid


We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.


Regards,
Sarvesh


Marked as answer

MI Mike-E February 2, 2023 08:56 AM UTC

Whoohoo!  Thank you very much Sarvesh and team!  Your efforts are greatly appreciated.



SG Suganya Gopinath Syncfusion Team February 6, 2023 05:13 AM UTC

Hi Mike, 

We are glad that the provided solution helped to solve the issue. Please get back to us for further assistance. 

We are marking this ticket as solved.

Regards,

Suganya Gopinath.



MI Mike-E February 14, 2023 02:16 PM UTC

I can confirm here that using 2.4.0.48 within my provided solution only call the database once now.  Thank you very very much out there Suganya, Sarvesh, and team. :)



MI Mike-E February 14, 2023 09:08 PM UTC

Hi Again 😇


Unfortunately, there appears to be another issue here.  If one request is ongoing (taking some time) this still gets called twice.


Please see the solution now, with this edit:

https://github.com/Mike-E-angelo/Stash/blob/master/Syncfusion.Grid.State/Pages/Index.razor#L44


Thank you for any further suggestions/consideration you can provide.



SP Sarveswaran Palani Syncfusion Team February 23, 2023 03:57 AM UTC

Hi Mike-E,

Sorry for the delay and inconvenience caused.

From your query, we would like to inform you that async functions render tasks simultaneously. If we hold a specific task using the delay await keyword, it will be held for 1000ms, and then the specific task starts rendering. This could be the reason for the read method called twice.


Please let us know if you have any further queries or concerns.

Regards,
Sarvesh



MI Mike-E February 23, 2023 09:27 AM UTC

Thank you for your reply, Sarvesh.  In my real-world case, I am not using `Task.Delay` of course.  I am make a call to my database which takes some time.  So much time, in fact, that it causes the control to call twice.  I still get two calls to the database as a result.

Is there some way to address this? 



SP Sarveswaran Palani Syncfusion Team March 6, 2023 07:51 AM UTC

Hi Mike-E,

Sorry for the delay.

We would like to inform you that the Read method is sufficient for synchronous operations and the ReadAsync method is used for asynchronous operations. We suspect that you are using the ReadAsync method for the synchronous operation, which may cause an issue based on your sample. So, please switch from synchronous to asynchronous operation. If still you’re facing an issue, please share the runnable sample with us so that we can validate it further at our end.


Regards,
Sarvesh



MI Mike-E March 6, 2023 10:54 AM UTC

Hi Sarvesh, thank you for your continued assistance, and no worries at all about the delay. :)

Please note that I provided an example of this here:

https://www.syncfusion.com/forums/177395/setpersistdataasync-causes-two-calls-to-datamanager?reply=SqcNqV

Please do let me know if I have misunderstood something and/or if there is any further information I can provide to help further diagnose this issue for you.



MI Mike-E May 18, 2023 06:51 PM UTC

Hi Sarvesh have you been able to look at the provided solution?  I still experience the same double-load problem and it is impacting performance.

Thank you for any further assistance,

Michael



MI Mike-E May 23, 2023 09:09 AM UTC

Hi, Sarvesh thank you for any update you can provide.  Please let me know if another ticket is needed.



SP Sarveswaran Palani Syncfusion Team May 24, 2023 04:08 AM UTC

Hi Mike,

Sorry for the inconvenience caused.

We'll validating your query with our development team. We'll update you shortly regarding an issue. If you would like to create a new ticket for easier follow-up, please feel free to do so. This will help us track and address your concerns more efficiently.

Regards,
Sarvesh



MI Mike-E May 24, 2023 06:17 PM UTC

Great thank you for the update Sarvesh, your patience and professionalism are greatly appreciated. I will stick tight on this thread then if it's OK. :)



SP Sarveswaran Palani Syncfusion Team May 31, 2023 03:17 AM UTC

Hi Mike,

Based on your query, it seems that you are encountering an issue where the read method is being called twice during component rendering. We suspect that this could be due to the simultaneous execution of async functions. When a specific task is delayed using the await keyword, it will be held for 1000ms before it starts rendering. This could be the reason why the read method is being called twice.


If you require some time to fetch data from the database before rendering the grid, we suggest using the delay method before rendering the grid. After the delay, you can proceed to render the grid using a Boolean variable to ensure that the read method is called only once.

Regards,
Sarvesh



MI Mike-E May 31, 2023 08:46 AM UTC

Hi Sarvesh thank you for your investigation and time looking into this.

To be certain, the Task.Delay call is meant to replicate a long-running SQL query.  The issue is that SfGrid calls this method twice if there is a long delay in the processing, leading to two calls to the database.  Shouldn't this boolean logic that you suggest be part of the SfGrid and not the developer's concern?  This is what was done with the original (synchronous) fix, after all.

Thank you for any further consideration toward addressing this performance issue.



MI Mike-E June 21, 2023 08:14 AM UTC

Hi Sarvesh,

I wanted to check in on this issue.  Can you provide an example solution that demonstrates your suggestion so that the get data method is not called twice?

Thank you for any further assistance you can provide,

Michael



SP Sarveswaran Palani Syncfusion Team June 23, 2023 03:54 AM UTC

Hi Mike-E,

Based on your request, we have prepared a sample solution that demonstrates our suggestion of calling the read method only once in a data manager. Please find the attached sample for your reference.


If you have any further questions or concerns, please feel free to let us know.

Regards,
Sarvesh


Attachment: SfBlazorGrid_DataManager_94055b4.zip


MI Mike-E June 23, 2023 12:07 PM UTC

Hi Sarvesh,

Thank you for taking the time to provide a solution.  Unfortunately, the solution you provided is synchronous, and the problem I am reporting now is in the asynchronous method:

public override async Task<object> ReadAsync(DataManagerRequest dm, string key = null)

The issue is when the `ReadAsync` takes significant time (e.g. database query call) the ReadAsync method ends up getting called twice by the SfGrid.

Please let me know if I can further assist in explaining the issue.

Thank you,

Michael



MI Mike-E June 28, 2023 05:48 PM UTC

Hi Sarvesh I wanted to check in on this performance issue that is making two calls to the database when it occurs.  Have you been able to see this in the solution I provided earlier?


Thank you for any assistance you can provide.



SP Sarveswaran Palani Syncfusion Team June 29, 2023 01:24 PM UTC

Hi Mike-E,

Sorry for the delay and inconvenience caused.

We have thoroughly investigated the issue you reported regarding the asynchronous method "ReadAsync" and the behavior of the data manager. After carefully reviewing your query and conducting tests using the provided sample, we have confirmed that the "ReadAsync" method does indeed call the data manager only once. We have attached a modified sample and a video demonstration to showcase this behavior.


Upon further analysis, we have identified a potential cause for the reported issue. It appears that the problem arises when the Task.Delay method is invoked within the Read/ReadAsync method. This can result in the data manager being called twice, leading to the undesired behavior you experienced. To resolve this issue, we recommend removing the Task.Delay method from your project. By doing so, you can overcome the reported problem and ensure that the data manager is called only once, as intended.

Regards,
Sarvesh


Attachment: SfBlazorGridModified_a87094db.zip


MI Mike-E June 29, 2023 07:08 PM UTC

Hi Sarvesh,


Thank you for your reply and investigation.  Please note that your CustomAdaptor does not use asynchronous methods and in fact runs 100% synchronously, thereby avoiding the reported issue.  Note that I receive the following warning about the `async` keyword via ReSharper analysis:




If you can, please kindly update your sample to use an EntityFramework Core DbContext or simply make a call to an external resource such as a database or web service.  You should plainly see the issue under such circumstances.

The Task.Delay is meant to emulate a call to the database.  Can you confirm this scenario, please?  I can confirm that I am seeing two calls to the database because data manager is calling ReadAsync twice.


Thank you for your continued assistance,

Michael



SP Sarveswaran Palani Syncfusion Team July 3, 2023 03:58 AM UTC

Hi Mike-E,

From your query, we have prepared a sample using Entity Framework and DbContext that runs asynchronously. However, we observed that the read method is called only once from our end. In order to further investigate and address your specific issue, we kindly request you to share your entire project with us. This will enable us to validate the problem at our end and provide an accurate solution. We have attached a sample for your reference, and we look forward to assisting you further.

Regards,
Sarvesh


Attachment: EFCore_DbContext_21914cfc.zip


MI Mike-E July 4, 2023 10:12 AM UTC

Thank you very much for your continued investigation Sarvesh. I found several issues with your SLN:


  1. The Syncfusion version was not the latest and I updated it.
  2. This sample does not use EFCore but regular SQL reader. This is OK because I was able to reproduce it with this, too.
  3. The ReadAsync does not use asynchronous calls. I have modified it so that it does.
  4. Most importantly, please recall that the premise of this issue is the call to `SetPersistDataAsync` which was missing. I have added it.

Please find the updated ZIP attached with the SLN/project.

I see four calls to ReadAsync when running it:


Please let me know if there is any further information that I can provide and I will assist you.


Attachment: EFGrid_8b1b4faa.zip



MI Mike-E July 11, 2023 08:48 AM UTC

Hi Sarvesh, I wanted to check in with you as I did not hear back from you regarding this performance issue.  Can you confirm the multiple calls via page load in the solution I provided you?


Please let me know if I can provide any further information, and I will assist you.



SP Sarveswaran Palani Syncfusion Team July 12, 2023 01:47 PM UTC

Hi Mike-E,

Sorry for the inconvenience caused.

Upon reviewing your last shared sample, we observed that the read method is being called four times when invoking the SetPersistData method. However, we would like to inform you that this issue has already been addressed in version 20.4.0.48.


Currently, we are in the process of validating your sample to ensure that the issue has indeed been resolved. We will thoroughly evaluate the sample and provide you with further details within two business days. We kindly request your patience during this time. Thank you for understanding.

Regards,
Sarvesh



MI Mike-E July 12, 2023 02:26 PM UTC

Great thank you very much for the reply and continued investigation @Sarvesh.


Please note that the 20.4.0.48 fix only addressed the synchronous scenario.  The issue we're exploring now is the asynchronous version.


Please further note that the solution I provided you has the following reference, which is greater than the above version:


```

<PackageReference Include="Syncfusion.Blazor.Grid" Version="22.1.37" />

```



MI Mike-E July 18, 2023 06:35 PM UTC

Hi Sarvesh, I wanted to check in with you as it has been more than two business days.  Please let me know if there is any further information that I can provide to help diagose this issue for you.



SP Sarveswaran Palani Syncfusion Team July 19, 2023 06:18 PM UTC

Hi Mike,

Apologize for the delay.

We are currently in the process of validating your query using different test cases. We assure you that we will thoroughly evaluate the issue and provide further information without any delay by July 21st. We appreciate your patience during this time. Thank you for understanding.

Regards,
Sarvesh



MI Mike-E July 22, 2023 08:38 AM UTC

We assure you that we will thoroughly evaluate the issue and provide further information without any delay by July 21st

Hi Sarvesh it is July 22nd and I have not heard anything.  Please let me know if I have misunderstood something about your pronouncement.



SP Sarveswaran Palani Syncfusion Team July 24, 2023 02:38 PM UTC

Hi Mike,

We sincere apologize for your frustration.

We have successfully replicated the mentioned issue at our end, wherein the read method is called four times asynchronously while invoking the SetPersistDataAsync method. We have thoroughly validated the reported issue through various test cases involving dynamic column value binding. However, we have not been able to determine the exact root cause of the problem yet.


We are currently investigating whether this issue is specific to the component or a more general issue. we will provide an update with a precise solution as soon as possible without any further delay. Your cooperation is highly appreciated as we strive to find a solution to this issue. Thank you for your patience and understanding.

Regards,
Sarvesh



MI Mike-E July 24, 2023 02:49 PM UTC

Horray!  Thank you very much for your patience and professionalism Sarvesh. :)  I am very happy to hear that this issue has been confirmed.  I look forward to any updates you may have going forward. 



SP Sarveswaran Palani Syncfusion Team July 28, 2023 03:43 AM UTC

Hi Mike-e,


We have considered it as a bug and logged an issue “SetPersistDataAsync method invokes Asynchronous Read method Multiple Times” for the same. Thank you for taking the time to report this issue and helping us to improve our product. At Syncfusion, we are committed to fix all validated defects (subject to technological feasibility and Product Development Life Cycle) and this fix will be included in any of our upcoming patch release. We'll update once, when patch get rolled out.


You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.


https://www.syncfusion.com/feedback/45689/setpersistdataasync-method-invokes-asynchronous-read-method-multiple-times


Disclaimer: “Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization”


Until then we appreciate your patience.


Regards,

Sarvesh




MI Mike-E July 28, 2023 09:36 AM UTC

Yay, this really made my day!  Thank you Sarvesh and team I greatly appreciate all your efforts out there.  You really support your product excellently, which is what really matters in the end.  Be proud!



SG Suganya Gopinath Syncfusion Team August 2, 2023 12:20 PM UTC

Thank you for the acknowledgement. We will get back once it is fixed. 



VN Vignesh Natarajan Syncfusion Team November 3, 2023 03:33 AM UTC

Hi Mike-e,

We are glad to announce that, we have included the issue “SetPersistDataAsync method invokes Asynchronous Read method Multiple Times” in our latest release.  So please upgrade to our latest version of Syncfusion NuGet package to resolve the reported issue. Please find the Nuget package for latest fixes and features from below.


Nuget : https://www.nuget.org/packages/Syncfusion.Blazor.Grid


We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance. 


Regards,

Vignesh Natarajan


Loader.
Up arrow icon