mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
Add limit parameter
This commit is contained in:
@@ -300,6 +300,18 @@ public final class BrowseCommandBuilder
|
||||
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) {
|
||||
if (!disableCache) {
|
||||
CacheKey key = new CacheKey(repository, request);
|
||||
|
||||
@@ -191,6 +191,17 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
|
||||
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 ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -232,6 +243,15 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
|
||||
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) {
|
||||
if (updater != null) {
|
||||
updater.accept(update);
|
||||
@@ -249,6 +269,10 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
|
||||
/** browse file objects recursive */
|
||||
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
|
||||
// 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;
|
||||
|
||||
@@ -147,6 +147,10 @@ public abstract class FileBaseCommandRequest
|
||||
this.revision = revision;
|
||||
}
|
||||
|
||||
public void setLimit(int limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -171,6 +175,10 @@ public abstract class FileBaseCommandRequest
|
||||
return revision;
|
||||
}
|
||||
|
||||
public int getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -208,4 +216,6 @@ public abstract class FileBaseCommandRequest
|
||||
|
||||
/** Field description */
|
||||
private String revision;
|
||||
|
||||
private int limit;
|
||||
}
|
||||
|
||||
@@ -236,6 +236,19 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase {
|
||||
.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) {
|
||||
return foList.stream()
|
||||
.filter(f -> name.equals(f.getName()))
|
||||
|
||||
Reference in New Issue
Block a user