From f371ee793cead3664398c6ee87091385767dff38 Mon Sep 17 00:00:00 2001 From: blankrain <731014656@qq.com> Date: Thu, 5 Dec 2019 17:57:33 +0800 Subject: [PATCH] for https://discuss.dgraph.io/t/performance-is-not-good-when-finding-the-paths-between-2-nodes-with-k-shortest/3533/2 --- query/shortest.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/query/shortest.go b/query/shortest.go index d8de9339c59..f738f2d7f11 100644 --- a/query/shortest.go +++ b/query/shortest.go @@ -202,6 +202,9 @@ func (sg *SubGraph) expandOut(ctx context.Context, rch <- err return } + if canSkipRing(adjacencyMap, toUID, fromUID) { + continue + } adjacencyMap[fromUID][toUID] = mapItem{ cost: cost, facet: facet, @@ -686,3 +689,12 @@ func createkroutesubgraph(ctx context.Context, kroutes []route) []*SubGraph { } return res } + +func canSkipRing(adjacencyMap map[uint64]map[uint64]mapItem, k, v uint64) bool { + if adjacencyMap[k] != nil { + if _, ok := adjacencyMap[k][v]; ok { + return true + } + } + return false +}