From e17934ae09d856eac3b61cf29c6ee0394912ef1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Wed, 14 Sep 2022 14:28:40 +0200 Subject: [PATCH] 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. --- gradle/changelog/lasy_loading.yaml | 2 ++ .../scm/repository/api/BrowseCommandBuilder.java | 12 ++++++++---- .../sonia/scm/repository/api/RepositoryService.java | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 gradle/changelog/lasy_loading.yaml diff --git a/gradle/changelog/lasy_loading.yaml b/gradle/changelog/lasy_loading.yaml new file mode 100644 index 0000000000..69373f4835 --- /dev/null +++ b/gradle/changelog/lasy_loading.yaml @@ -0,0 +1,2 @@ +- type: fixed + description: Lazy loading in the source view ([#2120](https://github.com/scm-manager/scm-manager/pull/2120)) diff --git a/scm-core/src/main/java/sonia/scm/repository/api/BrowseCommandBuilder.java b/scm-core/src/main/java/sonia/scm/repository/api/BrowseCommandBuilder.java index d3e8669a7c..30b5a3f60f 100644 --- a/scm-core/src/main/java/sonia/scm/repository/api/BrowseCommandBuilder.java +++ b/scm-core/src/main/java/sonia/scm/repository/api/BrowseCommandBuilder.java @@ -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 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 browseCommandFactory; /** the repsitory */ private final Repository repository; diff --git a/scm-core/src/main/java/sonia/scm/repository/api/RepositoryService.java b/scm-core/src/main/java/sonia/scm/repository/api/RepositoryService.java index d3b463a8bb..64ac0e541a 100644 --- a/scm-core/src/main/java/sonia/scm/repository/api/RepositoryService.java +++ b/scm-core/src/main/java/sonia/scm/repository/api/RepositoryService.java @@ -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); } /**