Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #719 from shrishrirang/dev-pagesize-pr
Browse files Browse the repository at this point in the history
Add support to configure page size during a pull operation
  • Loading branch information
phvannor committed Jun 11, 2015
2 parents 9f2472a + 519fadb commit 84fb0c2
Show file tree
Hide file tree
Showing 13 changed files with 307 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,32 @@ public static class MobileServiceSyncTableExtensions
/// </exception>
public static Task PullAsync(this IMobileServiceSyncTable table, string queryId, string query)
{
return table.PullAsync(queryId, query, null, CancellationToken.None);
return table.PullAsync(queryId, query, null, CancellationToken.None, pullOptions: null);
}

/// <summary>
/// Pulls all items that match the given query from the associated remote table. Supports incremental sync.
/// </summary>
/// <param name="table">The instance of table to execute pull on.</param>
/// <param name="queryId">
/// A string that uniquely identifies this query and is used to keep track of its sync state. Supplying this parameter enables incremental sync whenever the same key is used again. Must be 25 characters or less and contain only alphanumeric characters, dash, and underscore.
/// </param>
/// <param name="query">
/// An OData query that determines which items to
/// pull from the remote table.
/// </param>
/// <param name="pullOptions">
/// PullOptions that determine how to pull data from the remote table
/// </param>
/// <returns>
/// A task that completes when pull operation has finished.
/// </returns>
/// <exception cref="System.ArgumentException">
/// Thrown when <paramref name="queryId"/> does not match the regular expression <value>[a-zA-Z][a-zA-Z0-9_-]{0,24}</value>.
/// </exception>
public static Task PullAsync(this IMobileServiceSyncTable table, string queryId, string query, PullOptions pullOptions)
{
return table.PullAsync(queryId, query, null, CancellationToken.None, pullOptions);
}


Expand Down Expand Up @@ -62,9 +87,68 @@ public static Task PullAsync(this IMobileServiceSyncTable table, string queryId,
/// </exception>
public static Task PullAsync(this IMobileServiceSyncTable table, string queryId, string query, IDictionary<string, string> parameters, CancellationToken cancellationToken)
{
return table.PullAsync(queryId, query, parameters, true, cancellationToken: cancellationToken);
return table.PullAsync(queryId, query, parameters, true, cancellationToken: cancellationToken, pullOptions: null);
}

/// <summary>
/// Pulls all items that match the given query from the associated remote table. Supports incremental sync.
/// </summary>
/// <param name="table">The instance of table to execute pull on.</param>
/// <param name="queryId">
/// A string that uniquely identifies this query and is used to keep track of its sync state. Supplying this parameter enables incremental sync whenever the same key is used again. Must be 25 characters or less and contain only alphanumeric characters, dash, and underscore.
/// </param>
/// <param name="query">
/// An OData query that determines which items to
/// pull from the remote table.
/// </param>
/// <param name="parameters">
/// A dictionary of user-defined parameters and values to include in
/// the request URI query string.
/// </param>
/// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> token to observe
/// </param>
/// <param name="pullOptions">
/// PullOptions that determine how to pull data from the remote table
/// </param>
/// <returns>
/// A task that completes when pull operation has finished.
/// </returns>
/// <exception cref="System.ArgumentException">
/// Thrown when <paramref name="queryId"/> does not match the regular expression <value>[a-zA-Z][a-zA-Z0-9_-]{0,24}</value>.
/// </exception>
public static Task PullAsync(this IMobileServiceSyncTable table, string queryId, string query, IDictionary<string, string> parameters, CancellationToken cancellationToken, PullOptions pullOptions)
{
return table.PullAsync(queryId, query, parameters, true, cancellationToken: cancellationToken, pullOptions: pullOptions);
}

/// <summary>
/// Pulls all items that match the given query from the associated remote table. Supports incremental sync.
/// </summary>
/// <param name="queryId">
/// A string that uniquely identifies this query and is used to keep track of its sync state. Supplying this parameter enables incremental sync whenever the same key is used again.
/// </param>
/// <param name="query">
/// An OData query that determines which items to
/// pull from the remote table.
/// </param>
/// <param name="parameters">
/// A dictionary of user-defined parameters and values to include in
/// the request URI query string.
/// </param>
/// <param name="pushOtherTables">
/// Push other tables if this table is dirty.
/// </param>
/// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> token to observe
/// </param>
/// <returns>
/// A task that completes when pull operation has finished.
/// </returns>
public static Task PullAsync(this IMobileServiceSyncTable table, string queryId, string query,
IDictionary<string, string> parameters, bool pushOtherTables, CancellationToken cancellationToken)
{
return table.PullAsync(queryId, query, parameters, pushOtherTables, cancellationToken, pullOptions:null);
}

/// <summary>
/// Pulls all items that match the given query from the associated remote table.
/// </summary>
Expand All @@ -86,7 +170,34 @@ public static Task PullAsync(this IMobileServiceSyncTable table, string queryId,
/// </exception>
public static Task PullAsync<T, U>(this IMobileServiceSyncTable<T> table, string queryId, IMobileServiceTableQuery<U> query, CancellationToken cancellationToken)
{
return table.PullAsync(queryId, query, pushOtherTables: true, cancellationToken: cancellationToken);
return table.PullAsync(queryId, query, pushOtherTables: true, cancellationToken: cancellationToken, pullOptions: null);
}

/// <summary>
/// Pulls all items that match the given query from the associated remote table.
/// </summary>
/// <param name="table">The instance of table to execute pull on.</param>
/// <param name="queryId">
/// A string that uniquely identifies this query and is used to keep track of its sync state. Supplying this parameter enables incremental sync whenever the same key is used again. Must be 25 characters or less and contain only alphanumeric characters, dash, and underscore.
/// </param>
/// <param name="query">
/// An OData query that determines which items to
/// pull from the remote table.
/// </param>
/// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> token to observe
/// </param>
/// <param name="pullOptions">
/// PullOptions that determine how to pull data from the remote table
/// </param>
/// <returns>
/// A task that completes when pull operation has finished.
/// </returns>
/// <exception cref="System.ArgumentException">
/// Thrown when <paramref name="queryId"/> does not match the regular expression <value>[a-zA-Z][a-zA-Z0-9_-]{0,24}</value>.
/// </exception>
public static Task PullAsync<T, U>(this IMobileServiceSyncTable<T> table, string queryId, IMobileServiceTableQuery<U> query, CancellationToken cancellationToken, PullOptions pullOptions)
{
return table.PullAsync(queryId, query, pushOtherTables: true, cancellationToken: cancellationToken, pullOptions: pullOptions);
}

/// <summary>
Expand All @@ -109,7 +220,57 @@ public static Task PullAsync<T, U>(this IMobileServiceSyncTable<T> table, string
/// </exception>
public static Task PullAsync<T, U>(this IMobileServiceSyncTable<T> table, string queryId, IMobileServiceTableQuery<U> query)
{
return table.PullAsync(queryId, query, cancellationToken: CancellationToken.None);
return table.PullAsync(queryId, query, cancellationToken: CancellationToken.None, pullOptions: null);
}

/// <summary>
/// Pulls all items that match the given query
/// from the associated remote table.
/// </summary>
/// <param name="table">The instance of table to execute pull on.</param>
/// <param name="queryId">
/// A string that uniquely identifies this query and is used to keep track of its sync state. Supplying this parameter enables incremental sync whenever the same key is used again. Must be 25 characters or less and contain only alphanumeric characters, dash, and underscore.
/// </param>
/// <param name="query">
/// An OData query that determines which items to
/// pull from the remote table.
/// </param>
/// <param name="pullOptions">
/// PullOptions that determine how to pull data from the remote table
/// </param>
/// <returns>
/// A task that completes when pull operation has finished.
/// </returns>
/// <exception cref="System.ArgumentException">
/// Thrown when <paramref name="queryId"/> does not match the regular expression <value>[a-zA-Z][a-zA-Z0-9_-]{0,24}</value>.
/// </exception>
public static Task PullAsync<T, U>(this IMobileServiceSyncTable<T> table, string queryId, IMobileServiceTableQuery<U> query, PullOptions pullOptions)
{
return table.PullAsync(queryId, query, cancellationToken: CancellationToken.None, pullOptions: pullOptions);
}

/// <summary>
/// Pulls all items that match the given query from the associated remote table.
/// </summary>
/// <param name="queryId">
/// A string that uniquely identifies this query and is used to keep track of its sync state. Supplying this parameter enables incremental sync whenever the same key is used again.
/// </param>
/// <param name="query">
/// An OData query that determines which items to
/// pull from the remote table.
/// </param>
/// <param name="pushOtherTables">
/// Push other tables if this table is dirty
/// </param>
/// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> token to observe
/// </param>
/// <returns>
/// A task that completes when pull operation has finished.
/// </returns>
public static Task PullAsync<T, U>(this IMobileServiceSyncTable<T> table, string queryId,
IMobileServiceTableQuery<U> query, bool pushOtherTables, CancellationToken cancellationToken)
{
return table.PullAsync(queryId, query, pushOtherTables, cancellationToken, pullOptions: null);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Table\MobileServiceObjectReader.cs" />
<Compile Include="Table\Sync\PullOptions.cs" />
<Compile Include="Table\Sync\Queue\Operations\MobileServiceTableKind.cs" />
<Compile Include="Table\MobileServiceSystemColumns.cs" />
<Compile Include="Table\MobileServiceSystemProperties.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,13 @@ public interface IMobileServiceSyncTable<T> : IMobileServiceSyncTable
/// </param>
/// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> token to observe
/// </param>
/// <param name="pullOptions">
/// PullOptions that determine how to pull data from the remote table
/// </param>
/// <returns>
/// A task that completes when pull operation has finished.
/// </returns>
Task PullAsync<U>(string queryId, IMobileServiceTableQuery<U> query, bool pushOtherTables, CancellationToken cancellationToken);
Task PullAsync<U>(string queryId, IMobileServiceTableQuery<U> query, bool pushOtherTables, CancellationToken cancellationToken, PullOptions pullOptions);

/// <summary>
/// Deletes all the items in local table that match the query.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,13 @@ public interface IMobileServiceSyncTable
/// </param>
/// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> token to observe
/// </param>
/// <param name="pullOptions">
/// PullOptions that determine how to pull data from the remote table
/// </param>
/// <returns>
/// A task that completes when pull operation has finished.
/// </returns>
Task PullAsync(string queryId, string query, IDictionary<string, string> parameters, bool pushOtherTables, CancellationToken cancellationToken);
Task PullAsync(string queryId, string query, IDictionary<string, string> parameters, bool pushOtherTables, CancellationToken cancellationToken, PullOptions pullOptions);

/// <summary>
/// Deletes all the items in local table that match the query.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,13 @@ public async Task<JObject> LookupAsync(string tableName, string id)
/// <param name="reader">An instance of <see cref="MobileServiceObjectReader"/></param>
/// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> token to observe
/// </param>
/// <param name="pullOptions">
/// PullOptions that determine how to pull data from the remote table
/// </param>
/// <returns>
/// A task that completes when pull operation has finished.
/// </returns>
public async Task PullAsync(string tableName, MobileServiceTableKind tableKind, string queryId, string query, MobileServiceRemoteTableOptions options, IDictionary<string, string> parameters, IEnumerable<string> relatedTables, MobileServiceObjectReader reader, CancellationToken cancellationToken)
public async Task PullAsync(string tableName, MobileServiceTableKind tableKind, string queryId, string query, MobileServiceRemoteTableOptions options, IDictionary<string, string> parameters, IEnumerable<string> relatedTables, MobileServiceObjectReader reader, CancellationToken cancellationToken, PullOptions pullOptions)
{
await this.EnsureInitializedAsync();

Expand Down Expand Up @@ -233,7 +236,8 @@ public async Task PullAsync(string tableName, MobileServiceTableKind tableKind,
// let us not burden the server to calculate the count when we don't need it for pull
queryDescription.IncludeTotalCount = false;

var action = new PullAction(table, tableKind, this, queryId, queryDescription, parameters, relatedTables, this.opQueue, this.settings, this.Store, options, reader, cancellationToken);
var action = new PullAction(table, tableKind, this, queryId, queryDescription, parameters, relatedTables,
this.opQueue, this.settings, this.Store, options, pullOptions, reader, cancellationToken);
await this.ExecuteSyncAction(action);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public Task<IEnumerable<U>> ReadAsync<U>(IMobileServiceTableQuery<U> query)
return this.queryProvider.Execute(query);
}

public Task PullAsync<U>(string queryId, IMobileServiceTableQuery<U> query, bool pushOtherTables, CancellationToken cancellationToken)
public Task PullAsync<U>(string queryId, IMobileServiceTableQuery<U> query, bool pushOtherTables, CancellationToken cancellationToken, PullOptions pullOptions)
{
if (query == null)
{
throw new ArgumentNullException("query");
}
string queryString = this.queryProvider.ToODataString(query);

return this.PullAsync(queryId, queryString, query.Parameters, pushOtherTables, cancellationToken);
return this.PullAsync(queryId, queryString, query.Parameters, pushOtherTables, cancellationToken, pullOptions);
}

public Task PurgeAsync<U>(string queryId, IMobileServiceTableQuery<U> query, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ public Task<JToken> ReadAsync(string query)
return this.syncContext.ReadAsync(this.TableName, query);
}

public Task PullAsync(string queryId, string query, IDictionary<string, string> parameters, MobileServiceObjectReader reader, CancellationToken cancellationToken, params string[] relatedTables)
public Task PullAsync(string queryId, string query, IDictionary<string, string> parameters, MobileServiceObjectReader reader, CancellationToken cancellationToken, PullOptions pullOptions, params string[] relatedTables)
{
ValidateQueryId(queryId);

return this.syncContext.PullAsync(this.TableName, this.Kind, queryId, query, this.SupportedOptions, parameters, relatedTables, reader, cancellationToken);
return this.syncContext.PullAsync(this.TableName, this.Kind, queryId, query, this.SupportedOptions, parameters, relatedTables, reader, cancellationToken, pullOptions);
}

public Task PullAsync(string queryId, string query, IDictionary<string, string> parameters, bool pushOtherTables, CancellationToken cancellationToken)
public Task PullAsync(string queryId, string query, IDictionary<string, string> parameters, bool pushOtherTables, CancellationToken cancellationToken, PullOptions pullOptions)
{
ValidateQueryId(queryId);
return this.syncContext.PullAsync(this.TableName, this.Kind, queryId, query, this.SupportedOptions, parameters, pushOtherTables ? new string[0] : null, null, cancellationToken);
return this.syncContext.PullAsync(this.TableName, this.Kind, queryId, query, this.SupportedOptions, parameters, pushOtherTables ? new string[0] : null, null, cancellationToken, pullOptions);
}

public Task PurgeAsync(string queryId, string query, bool force, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// ----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// ----------------------------------------------------------------------------

using System;
using System.Globalization;

namespace Microsoft.WindowsAzure.MobileServices.Sync
{
public class PullOptions
{
private int _maxPageSize;

/// <summary>
/// Constructor
/// </summary>
public PullOptions()
{
MaxPageSize = 50;
}

/// <summary>
/// Maximum allowed size of a page while performing a pull operation.
/// </summary>
public int MaxPageSize
{
get { return _maxPageSize; }
set
{
if (value <= 0)
{
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture,
"Tried to set MaxPageSize to invalid value {0}", value));
}

_maxPageSize = value;
}
}
}
}
Loading

0 comments on commit 84fb0c2

Please sign in to comment.