Fix lazy loading in the source view (#2120)

The lazy loading feature implemented for git was broken,
because the repeated usage in the BrowserResultCollapser
has overwritten the request in the command. Therefore
the command could no longer update the cache in the
BrowseCommandBuilder.

To fix this, we now use a browse command factory (represented
by a simple supplier) that will create a dedicated command
implementation for each request issued in the collapser.
This commit is contained in:
René Pfeuffer
2022-09-14 14:28:40 +02:00
committed by GitHub
parent 0170760082
commit e17934ae09
3 changed files with 11 additions and 5 deletions

View File

@@ -0,0 +1,2 @@
- type: fixed
description: Lazy loading in the source view ([#2120](https://github.com/scm-manager/scm-manager/pull/2120))

View File

@@ -41,6 +41,7 @@ import sonia.scm.repository.spi.BrowseCommandRequest;
import java.io.IOException;
import java.io.Serializable;
import java.util.function.Supplier;
//~--- JDK imports ------------------------------------------------------------
@@ -80,21 +81,23 @@ public final class BrowseCommandBuilder
//~--- constructors ---------------------------------------------------------
/**
* Constructs a new {@link LogCommandBuilder}, this constructor should
* Constructs a new {@link BrowseCommandBuilder}, this constructor should
* only be called from the {@link RepositoryService}.
*
* @param cacheManager cache manager
* @param browseCommand implementation of the {@link BrowseCommand}
* @param repository repository to query
* @param preProcessorUtil
* @param preProcessorUtil this factory is used to create browse commands for the collapse feature
*/
BrowseCommandBuilder(CacheManager cacheManager, BrowseCommand browseCommand,
Repository repository, PreProcessorUtil preProcessorUtil)
Repository repository, PreProcessorUtil preProcessorUtil,
Supplier<BrowseCommand> browseCommandFactory)
{
this.cache = cacheManager.getCache(CACHE_NAME);
this.browseCommand = browseCommand;
this.repository = repository;
this.preProcessorUtil = preProcessorUtil;
this.browseCommandFactory = browseCommandFactory;
}
//~--- methods --------------------------------------------------------------
@@ -174,7 +177,7 @@ public final class BrowseCommandBuilder
private BrowserResult computeBrowserResult() throws IOException {
BrowserResult result = browseCommand.getBrowserResult(request);
if (result != null && !request.isRecursive() && request.isCollapse()) {
new BrowserResultCollapser().collapseFolders(browseCommand, request, result.getFile());
new BrowserResultCollapser().collapseFolders(browseCommandFactory.get(), request, result.getFile());
}
return result;
}
@@ -457,6 +460,7 @@ public final class BrowseCommandBuilder
/** Field description */
private final PreProcessorUtil preProcessorUtil;
private final Supplier<BrowseCommand> browseCommandFactory;
/** the repsitory */
private final Repository repository;

View File

@@ -205,7 +205,7 @@ public final class RepositoryService implements Closeable {
LOG.debug("create browse command for repository {}", repository);
return new BrowseCommandBuilder(cacheManager, provider.getBrowseCommand(),
repository, preProcessorUtil);
repository, preProcessorUtil, provider::getBrowseCommand);
}
/**