mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
Update cache after each file
This commit is contained in:
@@ -74,6 +74,7 @@ import java.util.Optional;
|
||||
import static java.util.Optional.empty;
|
||||
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
||||
import static sonia.scm.NotFoundException.notFound;
|
||||
import static sonia.scm.repository.spi.SyncAsyncExecutor.ExecutionType.ASYNCHRONOUS;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -97,6 +98,8 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
|
||||
private final SyncAsyncExecutor executor;
|
||||
|
||||
private BrowserResult browserResult;
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -124,9 +127,9 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
ObjectId revId = computeRevIdToBrowse(request, repo);
|
||||
|
||||
if (revId != null) {
|
||||
BrowserResult browserResult = new BrowserResult(revId.getName(), request.getRevision(), getEntry(repo, request, revId));
|
||||
browserResult = new BrowserResult(revId.getName(), request.getRevision(), getEntry(repo, request, revId));
|
||||
executor.execute(executionType -> {
|
||||
if (executionType == SyncAsyncExecutor.ExecutionType.ASYNCHRONOUS) {
|
||||
if (executionType == ASYNCHRONOUS) {
|
||||
request.updateCache(browserResult);
|
||||
logger.info("updated browser result for repository {}", repository.getNamespaceAndName());
|
||||
}
|
||||
@@ -207,7 +210,7 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
// don't show message and date for directories to improve performance
|
||||
if (!file.isDirectory() &&!request.isDisableLastCommit())
|
||||
{
|
||||
executor.execute(() -> {
|
||||
executor.execute(executionType -> {
|
||||
logger.trace("fetch last commit for {} at {}", path, revId.getName());
|
||||
RevCommit commit = getLatestCommit(repo, revId, path);
|
||||
|
||||
@@ -235,6 +238,10 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
if (commit != null) {
|
||||
file.setLastModified(GitUtil.getCommitTime(commit));
|
||||
file.setDescription(commit.getShortMessage());
|
||||
if (executionType == ASYNCHRONOUS && browserResult != null) {
|
||||
request.updateCache(browserResult);
|
||||
logger.info("updated browser result for repository {}", repository.getNamespaceAndName());
|
||||
}
|
||||
} else {
|
||||
logger.warn("could not find latest commit for {} on {}", path,
|
||||
revId);
|
||||
|
||||
@@ -39,6 +39,8 @@ import sonia.scm.repository.spi.SyncAsyncExecutors.AsyncExecutorStepper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -119,21 +121,34 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase {
|
||||
public void testAsynchronousBrowse() throws IOException {
|
||||
try (AsyncExecutorStepper executor = stepperAsynchronousExecutor()) {
|
||||
GitBrowseCommand command = new GitBrowseCommand(createContext(), repository, null, executor);
|
||||
FileObject root = command.getBrowserResult(new BrowseCommandRequest()).getFile();
|
||||
List<BrowserResult> updatedResults = new LinkedList<>();
|
||||
BrowseCommandRequest request = new BrowseCommandRequest(updatedResults::add);
|
||||
FileObject root = command.getBrowserResult(request).getFile();
|
||||
assertNotNull(root);
|
||||
|
||||
Collection<FileObject> foList = root.getChildren();
|
||||
|
||||
FileObject a = findFile(foList, "a.txt");
|
||||
FileObject b = findFile(foList, "b.txt");
|
||||
|
||||
assertFalse(a.isDirectory());
|
||||
assertNull("expected empty name before commit could have been read", a.getDescription());
|
||||
assertNull("expected empty date before commit could have been read", a.getLastModified());
|
||||
assertNull("expected empty name before commit could have been read", b.getDescription());
|
||||
assertNull("expected empty date before commit could have been read", b.getLastModified());
|
||||
|
||||
executor.next();
|
||||
|
||||
assertEquals(1, updatedResults.size());
|
||||
assertNotNull("expected correct name after commit could have been read", a.getDescription());
|
||||
assertNotNull("expected correct date after commit could have been read", a.getLastModified());
|
||||
assertNull("expected empty name before commit could have been read", b.getDescription());
|
||||
assertNull("expected empty date before commit could have been read", b.getLastModified());
|
||||
|
||||
executor.next();
|
||||
|
||||
assertEquals(2, updatedResults.size());
|
||||
assertNotNull("expected correct name after commit could have been read", b.getDescription());
|
||||
assertNotNull("expected correct date after commit could have been read", b.getLastModified());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ public final class SyncAsyncExecutors {
|
||||
return new AsyncExecutorStepper() {
|
||||
@Override
|
||||
public void close() {
|
||||
enterSemaphore.release(Integer.MAX_VALUE);
|
||||
exitSemaphore.release(Integer.MAX_VALUE);
|
||||
enterSemaphore.release(Integer.MAX_VALUE/2);
|
||||
exitSemaphore.release(Integer.MAX_VALUE/2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user