mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Improve notification policies view performance (#80209)
This commit is contained in:
parent
ddbe4d2bba
commit
ea4bfc23ca
@ -276,6 +276,12 @@ type RouteFilters = {
|
||||
|
||||
export const findRoutesMatchingFilters = (rootRoute: RouteWithID, filters: RouteFilters): RouteWithID[] => {
|
||||
const { contactPointFilter, labelMatchersFilter = [] } = filters;
|
||||
const hasFilter = contactPointFilter || labelMatchersFilter.length > 0;
|
||||
|
||||
// if filters are empty we short-circuit this function
|
||||
if (!hasFilter) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let matchedRoutes: RouteWithID[][] = [];
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { MatcherOperator, Route, RouteWithID } from 'app/plugins/datasource/alertmanager/types';
|
||||
|
||||
import {
|
||||
InhertitableProperties,
|
||||
computeInheritedTree,
|
||||
findMatchingRoutes,
|
||||
getInheritedProperties,
|
||||
@ -203,6 +204,18 @@ describe('getInheritedProperties()', () => {
|
||||
const childInherited = getInheritedProperties(parent, child);
|
||||
expect(childInherited).toHaveProperty('group_by', ['label']);
|
||||
});
|
||||
|
||||
// This scenario is technically impossible unless we have a bug in our code.
|
||||
// A route cannot both specify a receiver and inherit it from its parent at the same time.
|
||||
it('should inherit from parent instead of grandparent', () => {
|
||||
const parent: Route = { receiver: 'parent' };
|
||||
const parentInherited: InhertitableProperties = { receiver: 'grandparent', group_by: ['foo'] };
|
||||
const child: Route = {};
|
||||
|
||||
const childInherited = getInheritedProperties(parent, child, parentInherited);
|
||||
expect(childInherited).toHaveProperty('receiver', 'parent');
|
||||
expect(childInherited.group_by).toEqual(['foo']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('regular "undefined" values', () => {
|
||||
|
@ -160,9 +160,8 @@ function getInheritedProperties(
|
||||
childRoute: Route,
|
||||
propertiesParentInherited?: Partial<InhertitableProperties>
|
||||
) {
|
||||
const fullParentProperties = merge({}, parentRoute, propertiesParentInherited);
|
||||
|
||||
const inheritableProperties: InhertitableProperties = pick(fullParentProperties, INHERITABLE_KEYS);
|
||||
const propsFromParent: InhertitableProperties = pick(parentRoute, INHERITABLE_KEYS);
|
||||
const inheritableProperties: InhertitableProperties = merge({}, propertiesParentInherited, propsFromParent);
|
||||
|
||||
// TODO how to solve this TypeScript mystery?
|
||||
const inherited = reduce(
|
||||
|
Loading…
Reference in New Issue
Block a user