mirror of https://github.com/halo-dev/halo
fix: possible incorrect result set obtained by Gc synchronizer when sartup (#5325)
#### What type of PR is this? /kind bug /area core /milestone 2.13.x #### What this PR does / why we need it: 修复启动时 GcSynchronizer 没有精准过滤出所需数据导致内存占用会出现较高峰值的问题 #### Which issue(s) this PR fixes: Fixes #5324 #### Does this PR introduce a user-facing change? ```release-note 修复启动时 GcSynchronizer 没有精准过滤出所需数据导致内存占用会出现较高峰值的问题 ```pull/5301/head^2
parent
dcef5d4157
commit
06a44d05dc
|
@ -1,9 +1,6 @@
|
|||
package run.halo.app.extension.gc;
|
||||
|
||||
import static run.halo.app.extension.Comparators.compareCreationTimestamp;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import run.halo.app.extension.Extension;
|
||||
import run.halo.app.extension.ExtensionClient;
|
||||
|
@ -64,8 +61,6 @@ class GcSynchronizer implements Synchronizer<GcRequest> {
|
|||
if (event instanceof SchemeRegistered registeredEvent) {
|
||||
var newScheme = registeredEvent.getNewScheme();
|
||||
listDeleted(newScheme.type()).forEach(watcher::onDelete);
|
||||
client.list(newScheme.type(), deleted(), compareCreationTimestamp(true))
|
||||
.forEach(watcher::onDelete);
|
||||
}
|
||||
});
|
||||
client.watch(watcher);
|
||||
|
@ -77,16 +72,8 @@ class GcSynchronizer implements Synchronizer<GcRequest> {
|
|||
<E extends Extension> List<E> listDeleted(Class<E> type) {
|
||||
var options = new ListOptions()
|
||||
.setFieldSelector(
|
||||
FieldSelector.of(QueryFactory.all("metadata.deletionTimestamp"))
|
||||
FieldSelector.of(QueryFactory.isNotNull("metadata.deletionTimestamp"))
|
||||
);
|
||||
return client.listAll(type, options, Sort.by("metadata.creationTimestamp"))
|
||||
.stream()
|
||||
.sorted(compareCreationTimestamp(true))
|
||||
.toList();
|
||||
return client.listAll(type, options, Sort.by(Sort.Order.asc("metadata.creationTimestamp")));
|
||||
}
|
||||
|
||||
private <E extends Extension> Predicate<E> deleted() {
|
||||
return extension -> extension.getMetadata().getDeletionTimestamp() != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import run.halo.app.extension.GroupVersionKind;
|
|||
import run.halo.app.extension.ListOptions;
|
||||
import run.halo.app.extension.ListResult;
|
||||
import run.halo.app.extension.PageRequest;
|
||||
import run.halo.app.extension.index.query.All;
|
||||
import run.halo.app.extension.index.query.QueryIndexViewImpl;
|
||||
import run.halo.app.extension.router.selector.FieldSelector;
|
||||
import run.halo.app.extension.router.selector.LabelSelector;
|
||||
|
@ -155,12 +154,13 @@ public class IndexedQueryEngineImpl implements IndexedQueryEngine {
|
|||
stopWatch.stop();
|
||||
|
||||
stopWatch.start("retrieve matched metadata names");
|
||||
var hasLabelSelector = hasLabelSelector(options.getLabelSelector());
|
||||
final List<String> matchedByLabels = hasLabelSelector
|
||||
? retrieveForLabelMatchers(options.getLabelSelector().getMatchers(), fieldPathEntryMap,
|
||||
allMetadataNames)
|
||||
: allMetadataNames;
|
||||
if (hasLabelSelector(options.getLabelSelector())) {
|
||||
var matchedByLabels = retrieveForLabelMatchers(options.getLabelSelector().getMatchers(),
|
||||
fieldPathEntryMap, allMetadataNames);
|
||||
if (allMetadataNames.size() != matchedByLabels.size()) {
|
||||
indexView.removeByIdNotIn(new TreeSet<>(matchedByLabels));
|
||||
}
|
||||
}
|
||||
stopWatch.stop();
|
||||
|
||||
stopWatch.start("retrieve matched metadata names by fields");
|
||||
|
@ -188,8 +188,6 @@ public class IndexedQueryEngineImpl implements IndexedQueryEngine {
|
|||
}
|
||||
|
||||
boolean hasFieldSelector(FieldSelector fieldSelector) {
|
||||
return fieldSelector != null
|
||||
&& fieldSelector.query() != null
|
||||
&& !(fieldSelector.query() instanceof All);
|
||||
return fieldSelector != null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue