mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 17:26:22 +01:00
Add limit parameter
This commit is contained in:
@@ -300,6 +300,18 @@ public final class BrowseCommandBuilder
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Limit the number of result files to <code>limit</code> entries.
|
||||||
|
*
|
||||||
|
* @param limit The maximal number of files this request shall return.
|
||||||
|
*
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public BrowseCommandBuilder setLimit(int limit) {
|
||||||
|
request.setLimit(limit);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
private void updateCache(BrowserResult updatedResult) {
|
private void updateCache(BrowserResult updatedResult) {
|
||||||
if (!disableCache) {
|
if (!disableCache) {
|
||||||
CacheKey key = new CacheKey(repository, request);
|
CacheKey key = new CacheKey(repository, request);
|
||||||
|
|||||||
@@ -191,6 +191,17 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
|
|||||||
this.recursive = recursive;
|
this.recursive = recursive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Limit the number of result files to <code>limit</code> entries.
|
||||||
|
*
|
||||||
|
* @param limit The maximal number of files this request shall return.
|
||||||
|
*
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public void setLimit(int limit) {
|
||||||
|
this.limit = limit;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -232,6 +243,15 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
|
|||||||
return recursive;
|
return recursive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the limit for the number of result files.
|
||||||
|
*
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public int getLimit() {
|
||||||
|
return limit;
|
||||||
|
}
|
||||||
|
|
||||||
public void updateCache(BrowserResult update) {
|
public void updateCache(BrowserResult update) {
|
||||||
if (updater != null) {
|
if (updater != null) {
|
||||||
updater.accept(update);
|
updater.accept(update);
|
||||||
@@ -249,6 +269,10 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
|
|||||||
/** browse file objects recursive */
|
/** browse file objects recursive */
|
||||||
private boolean recursive = false;
|
private boolean recursive = false;
|
||||||
|
|
||||||
|
|
||||||
|
/** Limit the number of result files to <code>limit</code> entries. */
|
||||||
|
private int limit = 1000;
|
||||||
|
|
||||||
// WARNING / TODO: This field creates a reverse channel from the implementation to the API. This will break
|
// WARNING / TODO: This field creates a reverse channel from the implementation to the API. This will break
|
||||||
// whenever the API runs in a different process than the SPI (for example to run explicit hosts for git repositories).
|
// whenever the API runs in a different process than the SPI (for example to run explicit hosts for git repositories).
|
||||||
private final transient Consumer<BrowserResult> updater;
|
private final transient Consumer<BrowserResult> updater;
|
||||||
|
|||||||
@@ -147,6 +147,10 @@ public abstract class FileBaseCommandRequest
|
|||||||
this.revision = revision;
|
this.revision = revision;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLimit(int limit) {
|
||||||
|
this.limit = limit;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -171,6 +175,10 @@ public abstract class FileBaseCommandRequest
|
|||||||
return revision;
|
return revision;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getLimit() {
|
||||||
|
return limit;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -208,4 +216,6 @@ public abstract class FileBaseCommandRequest
|
|||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private String revision;
|
private String revision;
|
||||||
|
|
||||||
|
private int limit;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -236,6 +236,19 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase {
|
|||||||
.containsExactly(of(42L));
|
.containsExactly(of(42L));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBrowseLimit() throws IOException {
|
||||||
|
BrowseCommandRequest request = new BrowseCommandRequest();
|
||||||
|
request.setLimit(2);
|
||||||
|
FileObject root = createCommand()
|
||||||
|
.getBrowserResult(request).getFile();
|
||||||
|
assertNotNull(root);
|
||||||
|
|
||||||
|
Collection<FileObject> foList = root.getChildren();
|
||||||
|
|
||||||
|
assertThat(foList).hasSize(2);
|
||||||
|
}
|
||||||
|
|
||||||
private FileObject findFile(Collection<FileObject> foList, String name) {
|
private FileObject findFile(Collection<FileObject> foList, String name) {
|
||||||
return foList.stream()
|
return foList.stream()
|
||||||
.filter(f -> name.equals(f.getName()))
|
.filter(f -> name.equals(f.getName()))
|
||||||
|
|||||||
Reference in New Issue
Block a user