0
votes

Working with an Azure Mobile App with Node.js backend. I got everything working, kind of. After setting up Offline Sync it is taking about 8 minutes to sync what should be 30 seconds. After debugging the app I found everything client side is working great. Reviewing the logs on the website I see the "read script" running repeatedly. It literally runs the read script every second, up until it finally finishes.

Is this behavior expected?

It hangs in SyncAsync() while awaiting LocalCards.PullAsync

Read Script

var table = module.exports = require('azure-mobile-apps').table();

table.read(function (context) 
{
 console.log('Attempting table read');
 return context.execute();
 });

App Code

private async Task InitLocalStoreAsync()
     {
        if (!App.MobileService.SyncContext.IsInitialized)
        {
            var store = new MobileServiceSQLiteStore("localsync32.db");
            store.DefineTable<Nname>();
            await App.MobileService.SyncContext.InitializeAsync(store);
        }

        await SyncAsync();
        await RefreshNcards();
    }
private async Task SyncAsync()
    {
        String errorString = null;
        string unique = DateTime.Now.Ticks.ToString() + DateTime.UtcNow.TimeOfDay.ToString();
        try
        {
            await LocalCards.PullAsync("Nnames "+unique,LocalCards.CreateQuery()); // first param is query ID, used for incremental sync
        }

        catch (Exception ex)
        {
            errorString = "Pull failed: " + ex.Message +
              "\n\nIf you are still in an offline scenario, " +
              "you can try your Pull again when connected with your Mobile Serice.";
        }

        if (errorString != null)
        {
            MessageDialog d = new MessageDialog(errorString);
            await d.ShowAsync();
        }
    }
1

1 Answers

0
votes

Apparently the PullAsync() command limits the query results to 50 per trip. So in my code I was only pulling 50 items at a time. To fix I added a pull options Param with a max page size:

    private async Task SyncAsync()
    {
        String errorString = null;
        PullOptions pageSize = new PullOptions { MaxPageSize =1000 };

        try
        {
            await LocalCards.PullAsync("Nname",LocalCards.CreateQuery(), pullOptions: pageSize); // first param is query ID, used for incremental sync
        }

        catch (Exception ex)
        {
            errorString = "Pull failed: " + ex.Message +
              "\n\nIf you are still in an offline scenario, " +
              "you can try your Pull again when connected with your Mobile Serice.";
        }

        if (errorString != null)
        {
            MessageDialog d = new MessageDialog(errorString);
            await d.ShowAsync();
        }
    }