mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-06 14:49:32 +02:00
Clear caches before rebuilding index
This is a follow-up to #202 Pushed-by: Rene Pfeuffer<rene.pfeuffer@cloudogu.com> Co-authored-by: René Pfeuffer<rene.pfeuffer@cloudogu.com>
This commit is contained in:
@@ -97,6 +97,7 @@ public class InvalidationResource {
|
||||
)
|
||||
public void invalidateSearchIndex() {
|
||||
ConfigurationPermissions.write("global").check();
|
||||
invalidateCaches();
|
||||
indexRebuilder.rebuildAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
|
||||
package sonia.scm.search;
|
||||
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -31,16 +34,21 @@ public class IndexRebuilder {
|
||||
|
||||
private final SearchEngine searchEngine;
|
||||
private final Set<Indexer> indexers;
|
||||
private final RepositoryManager repositoryManager;
|
||||
|
||||
@Inject
|
||||
public IndexRebuilder(SearchEngine searchEngine, Set<Indexer> indexers) {
|
||||
public IndexRebuilder(SearchEngine searchEngine, Set<Indexer> indexers, RepositoryManager repositoryManager) {
|
||||
this.searchEngine = searchEngine;
|
||||
this.indexers = indexers;
|
||||
this.repositoryManager = repositoryManager;
|
||||
}
|
||||
|
||||
public void rebuildAll() {
|
||||
for (Indexer indexer : indexers) {
|
||||
searchEngine.forType(indexer.getType()).update(indexer.getReIndexAllTask());
|
||||
repositoryManager.getAll().forEach(
|
||||
repository -> ScmEventBus.getInstance().post(new ReindexRepositoryEvent(repository))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,12 +107,13 @@ class InvalidationResourceTest {
|
||||
|
||||
@Test
|
||||
@SubjectAware(permissions = {"configuration:write:global"})
|
||||
void shouldReIndexAll() throws URISyntaxException {
|
||||
void shouldReIndexAllWithClearedCaches() throws URISyntaxException {
|
||||
MockHttpResponse response = invokeReIndex();
|
||||
|
||||
assertThat(response.getStatus()).isEqualTo(204);
|
||||
|
||||
verify(indexRebuilder).rebuildAll();
|
||||
verify(cacheManager).clearAllCaches();
|
||||
}
|
||||
|
||||
private MockHttpResponse invokeReIndex() throws URISyntaxException {
|
||||
|
||||
Reference in New Issue
Block a user