Is there a more elegant solution for syncing
Question
Application Type
Mobile

Hello all-

Happy Holidays!

I would like to run a foreach on a server data sync.  I know you should try to cut done on you server requests but I need to update a progress bar and this is the only way I have figured out how to get close.

Is there a more elegant way to do this?

Thank you in advance

Andy



Hello Andrew,


Do you need to update the progress bar for each item synched? If you send to the server by batches you can reduce the amount of server requests in your sync. Also you can update the progress bar at each batch - 10, 50, 100, etc. depending on your use case.

I believe this is the most efficient way to display progress bar percentage and reduce the amount of server calls.


Best regards,

Gonçalo Condeça.

How would I brake it down in batches?

Hello Andrew,


Follows a list of steps to follow that may help you:

  • Instead of fetching everything from the local storage select only 10 records, for example, and add a filter by LastSyncId and a sort by Id
  • Your server action should change to receive a list of records instead of only one record
  • Perform the iteration and creation of records inside the server action
  • Create on the client action an output parameter lastSynchedId and at the end of the client action change the output value to the last Id synched
  • Create on the client action an output parameter isFetchMore and at the end of the client action change the output value to true if the amount of records synched where the same as your limit previously defined (10 in the example that I provided)
  • Create a new client action where you call the client action that we have been mentioning and after add an if statement to check the isFetchMore value. If true call the client action again passing the lastSynchedId provided by the first call to the action. If false you can end the flow.

Hope this helps.


Best regards,

Gonçalo Condeça.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.