Fetch further data only when they're requested (#6976)

This commit is contained in:
Zhenxu Ke 2021-05-20 10:43:16 +08:00 committed by GitHub
parent 97c42d2f86
commit 6c90a954ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 2 deletions

View File

@ -20,6 +20,7 @@ package org.apache.skywalking.oap.query.graphql.resolver;
import com.coxautodev.graphql.tools.GraphQLQueryResolver;
import graphql.schema.DataFetchingEnvironment;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -79,7 +80,8 @@ public class AlarmQuery implements GraphQLQueryResolver {
}
public Alarms getAlarm(final Duration duration, final Scope scope, final String keyword,
final Pagination paging, final List<Tag> tags) throws Exception {
final Pagination paging, final List<Tag> tags,
final DataFetchingEnvironment env) throws Exception {
Integer scopeId = null;
if (scope != null) {
scopeId = scope.getScopeId();
@ -94,7 +96,14 @@ public class AlarmQuery implements GraphQLQueryResolver {
}
Alarms alarms = getQueryService().getAlarm(
scopeId, keyword, paging, startSecondTB, endSecondTB, tags);
return findRelevantEvents(alarms, conditionPrototype);
final boolean selectEvents = env.getSelectionSet().get().entrySet().stream().anyMatch(it -> it.getKey().contains("/events/"));
if (selectEvents) {
return findRelevantEvents(alarms, conditionPrototype);
}
return alarms;
}
private Alarms findRelevantEvents(