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

Feature/revision limits #202

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/CouchDB.Driver/CouchDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,34 @@ public async Task<CouchDatabaseInfo> GetInfoAsync(CancellationToken cancellation
.ConfigureAwait(false);
}

/// <inheritdoc />
public async Task<int> GetRevisionLimitAsync(CancellationToken cancellationToken = default)
{
return Convert.ToInt32(await NewRequest()
.AppendPathSegment("_revs_limit")
.GetStringAsync(cancellationToken)
.SendRequestAsync()
.ConfigureAwait(false));
}

/// <inheritdoc />
public async Task SetRevisionLimitAsync(int limit, CancellationToken cancellationToken = default)
{
using var content = new StringContent(limit.ToString());

OperationResult result = await NewRequest()
.AppendPathSegment("_revs_limit")
.PutAsync(content, cancellationToken)
.ReceiveJson<OperationResult>()
.SendRequestAsync()
.ConfigureAwait(false);

if (!result.Ok)
{
throw new CouchException("Something wrong happened while updating the revision limit.");
}
}

#endregion

#region Override
Expand Down
15 changes: 15 additions & 0 deletions src/CouchDB.Driver/ICouchDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,21 @@ Task<string> DownloadAttachmentAsync(CouchAttachment attachment, string localFol
/// <returns>A task that represents the asynchronous operation. The task result contains the database information.</returns>
Task<CouchDatabaseInfo> GetInfoAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Gets the revision limit for the specified database.
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the database information.</returns>
Task<int> GetRevisionLimitAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Sets the revision limit for the specified database.
/// </summary>
/// <param name="limit">The limit to set.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the database information.</returns>
Task SetRevisionLimitAsync(int limit, CancellationToken cancellationToken = default);

/// <summary>
/// Get an empty request that targets the current database.
/// </summary>
Expand Down
23 changes: 23 additions & 0 deletions tests/CouchDB.Driver.UnitTests/Database_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,29 @@ public async Task SecurityInfo_Put()
.WithRequestJson(securityInfo);
}


[Fact]
public async Task GetRevLimit()
{
using var httpTest = new HttpTest();
await _rebels.GetRevisionLimitAsync();
httpTest
.ShouldHaveCalled("http://localhost/rebels/_rev_limit")
.WithVerb(HttpMethod.Get);
}

[Fact]
public async Task SetRevLimit()
{
using var httpTest = new HttpTest();
// Operation response
httpTest.RespondWithJson(new { ok = true });

await _rebels.SetRevisionLimitAsync(10);
httpTest
.ShouldHaveCalled("http://localhost/rebels/_rev_limit")
.WithVerb(HttpMethod.Put);
}
#endregion

public ValueTask DisposeAsync()
Expand Down
Loading