Commit 01935da7 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[graph] fixes to maximum recursion error when there is a large number

of edges in graph
parent 424681d5
......@@ -77,6 +77,6 @@
"xhr2": "^0.2.1"
},
"optionalDependencies": {
"purescript-language-server": "^0.15.2"
"purescript-language-server": "^0.17.1"
}
}
......@@ -124,6 +124,7 @@ pkgs.mkShell {
pkgs.esbuild
pkgs.minify
pkgs.nodejs
#pkgs.nodePackages.purescript-language-server
pkgs.python # needed for msgpack etc
repl
serve
......
......@@ -16,7 +16,7 @@ import Data.Tuple.Nested ((/\))
import DOM.Simple.Types (Element)
import Effect (Effect)
import Effect.Class.Console (error)
import Effect.Timer (TimeoutId, clearTimeout)
import Effect.Timer (TimeoutId, clearTimeout, setTimeout)
import FFI.Simple ((.=))
import Gargantext.Hooks.Sigmax.ForceAtlas2 as ForceAtlas
import Gargantext.Hooks.Sigmax.Graphology as Graphology
......@@ -24,6 +24,7 @@ import Gargantext.Hooks.Sigmax.Sigma as Sigma
import Gargantext.Hooks.Sigmax.Types as ST
import Gargantext.Utils.Console as C
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Seq as GSeq
import Gargantext.Utils.Set as GSet
import Prelude (Unit, bind, discard, flip, map, not, pure, unit, ($), (&&), (*>), (<<<), (<>), (>>=), (+), (>), negate, (/=), (==), (<$>))
import Reactix as R
......@@ -229,7 +230,9 @@ performDiff sigma g = do
-- console.log2 "[performDiff] removeNodes" removeNodes
-- console.log2 "[performDiff] removeEdges" removeEdges
traverse_ (Graphology.addNode sigmaGraph) addNodes
traverse_ (Graphology.addEdge sigmaGraph) addEdges
--traverse_ (Graphology.addEdge sigmaGraph) addEdges
-- insert edges in batches, otherwise a maximum recursion error is thrown
traverse_ (\edges -> setTimeout 100 $ traverse_ (Graphology.addEdge sigmaGraph) edges) $ GSeq.groupBy 5000 addEdges
traverse_ (Graphology.removeEdge sigmaGraph) removeEdges
traverse_ (Graphology.removeNode sigmaGraph) removeNodes
traverse_ (Graphology.updateEdge sigmaGraph) updateEdges
......@@ -274,8 +277,6 @@ sigmaDiff sigmaGraph gControls = { add, remove, update }
ST.nodesFilter (\n -> not (Set.member n.id sigmaNodeIds)) gControls
addEdges = ST.graphEdges addGC
addNodes = ST.graphNodes addGC
-- addEdges = Seq.empty
-- addNodes = ST.graphNodes addGC
-- Remove nodes/edges from `sigmaGraph` which aren't in
-- `gControls`
......@@ -283,10 +284,13 @@ sigmaDiff sigmaGraph gControls = { add, remove, update }
removeNodes = Set.difference sigmaNodeIds (Set.fromFoldable gcNodeIds)
commonNodeIds = Set.intersection sigmaNodeIds $ Set.fromFoldable gcNodeIds
commonNodes = Seq.filter (\n -> Set.member n.id commonNodeIds) sigmaNodes
commonEdgeIds = Set.intersection sigmaEdgeIds $ Set.fromFoldable gcEdgeIds
sigmaNodeIdsMap = Map.fromFoldable $ Seq.map (\n -> Tuple n.id n) sigmaNodes
sigmaEdgeIdsMap = Map.fromFoldable $ Seq.map (\e -> Tuple e.id e) sigmaEdges
updateEdges = Seq.filter (\e -> Just e /= Map.lookup e.id sigmaEdgeIdsMap) gcEdges
commonEdges = Seq.filter (\e -> Set.member e.id commonEdgeIds) sigmaEdges
sigmaNodeIdsMap = Map.fromFoldable $ Seq.map (\n -> Tuple n.id n) commonNodes --sigmaNodes
sigmaEdgeIdsMap = Map.fromFoldable $ Seq.map (\e -> Tuple e.id e) commonEdges --sigmaEdges
-- updateEdges = Seq.filter (\e -> Just e /= Map.lookup e.id sigmaEdgeIdsMap) gcEdges
updateEdges = Seq.empty
-- Find nodes for which `ST.compareNodes` returns `false`, i.e. nodes differ
updateNodes = Seq.filter (\n -> (ST.compareNodes n <$> (Map.lookup n.id sigmaNodeIdsMap)) == Just false) gcNodes
-- updateEdges = Seq.empty
......
module Gargantext.Utils.Seq (mapMaybe) where
module Gargantext.Utils.Seq (groupBy, mapMaybe) where
import Data.Array ((:))
import Data.Maybe (Maybe, maybe)
import Data.Sequence (Seq, concatMap, empty, singleton)
import Data.Sequence (Seq, concatMap, empty, null, singleton, splitAt)
import Data.Tuple (Tuple(..))
import Gargantext.Prelude ((<<<))
mapMaybe :: forall a b. (a -> Maybe b) -> Seq a -> Seq b
mapMaybe f = concatMap (maybe empty singleton <<< f)
-- | Group a given `Seq` into list of `Seq`'s of length `n` (last one can be shorter)
groupBy :: forall a. Int -> Seq a -> Array (Seq a)
groupBy n s =
if null s
then []
else
let (Tuple hd tl) = splitAt n s in
(hd:groupBy n tl)
......@@ -8577,14 +8577,15 @@ punycode@^2.1.0, punycode@^2.1.1:
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
purescript-language-server@^0.15.2:
version "0.15.4"
resolved "https://registry.yarnpkg.com/purescript-language-server/-/purescript-language-server-0.15.4.tgz#0707891b0b91a72453d3bfda6a62f29f06b0d32f"
integrity sha512-llUv605I8yvraO98rb5RmmqPdpWBno7IpIlgNlX3Nq3Q4lvB7G0OxGK89JuAoVZ8T/xkTzhjyuzw0sty0DoY3Q==
purescript-language-server@^0.17.1:
version "0.17.1"
resolved "https://registry.yarnpkg.com/purescript-language-server/-/purescript-language-server-0.17.1.tgz#1240dbdf750b9d34fe394560b51d70a5d019e224"
integrity sha512-o/YpvFMOXp5/UqfFjed8+pwZwttg1QpI3iqkHlMB16AW8MRYGVwTAw1zV8MGqazFFat5j3+IJEUHhaeFON0EfA==
dependencies:
shell-quote "^1.7.2"
uuid "^3.3.2"
vscode-languageserver "^6.1.1"
vscode-jsonrpc "^8.0.0-next.2"
vscode-languageserver "^8.0.0-next.2"
vscode-languageserver-textdocument "^1.0.1"
vscode-uri "^2.1.1"
which "^2.0.2"
......@@ -10694,7 +10695,12 @@ vscode-jsonrpc@6.0.0:
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-6.0.0.tgz#108bdb09b4400705176b957ceca9e0880e9b6d4e"
integrity sha512-wnJA4BnEjOSyFMvjZdpiOwhSq9uDoK8e/kpRJDTaMYzwlkrhG1fwDIZI94CLsLzlCK5cIbMMtFlJlfR57Lavmg==
vscode-languageserver-protocol@3.16.0, vscode-languageserver-protocol@^3.15.3:
vscode-jsonrpc@8.0.2, vscode-jsonrpc@^8.0.0-next.2:
version "8.0.2"
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-8.0.2.tgz#f239ed2cd6004021b6550af9fd9d3e47eee3cac9"
integrity sha512-RY7HwI/ydoC1Wwg4gJ3y6LpU9FJRZAUnTYMXthqhFXXu77ErDd/xkREpGuk4MyYkk4a+XDWAMqe0S3KkelYQEQ==
vscode-languageserver-protocol@3.16.0:
version "3.16.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.16.0.tgz#34135b61a9091db972188a07d337406a3cdbe821"
integrity sha512-sdeUoAawceQdgIfTI+sdcwkiK2KU+2cbEYA0agzM2uqaUy2UpnnGHtWTHVEtS0ES4zHU0eMFRGN+oQgDxlD66A==
......@@ -10702,6 +10708,14 @@ vscode-languageserver-protocol@3.16.0, vscode-languageserver-protocol@^3.15.3:
vscode-jsonrpc "6.0.0"
vscode-languageserver-types "3.16.0"
vscode-languageserver-protocol@3.17.2:
version "3.17.2"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.2.tgz#beaa46aea06ed061576586c5e11368a9afc1d378"
integrity sha512-8kYisQ3z/SQ2kyjlNeQxbkkTNmVFoQCqkmGrzLH6A9ecPlgTbp3wDTnUNqaUxYr4vlAcloxx8zwy7G5WdguYNg==
dependencies:
vscode-jsonrpc "8.0.2"
vscode-languageserver-types "3.17.2"
vscode-languageserver-textdocument@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/vscode-languageserver-textdocument/-/vscode-languageserver-textdocument-1.0.1.tgz#178168e87efad6171b372add1dea34f53e5d330f"
......@@ -10712,12 +10726,10 @@ vscode-languageserver-types@3.16.0:
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0.tgz#ecf393fc121ec6974b2da3efb3155644c514e247"
integrity sha512-k8luDIWJWyenLc5ToFQQMaSrqCHiLwyKPHKPQZ5zz21vM+vIVUSvsRpcbiECH4WR88K2XZqc4ScRcZ7nk/jbeA==
vscode-languageserver@^6.1.1:
version "6.1.1"
resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-6.1.1.tgz#d76afc68172c27d4327ee74332b468fbc740d762"
integrity sha512-DueEpkUAkD5XTR4MLYNr6bQIp/UFR0/IPApgXU3YfCBCB08u2sm9hRCs6DxYZELkk++STPjpcjksR2H8qI3cDQ==
dependencies:
vscode-languageserver-protocol "^3.15.3"
vscode-languageserver-types@3.17.2:
version "3.17.2"
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.17.2.tgz#b2c2e7de405ad3d73a883e91989b850170ffc4f2"
integrity sha512-zHhCWatviizPIq9B7Vh9uvrH6x3sK8itC84HkamnBWoDFJtzBf7SWlpLCZUit72b3os45h6RWQNC9xHRDF8dRA==
vscode-languageserver@^7.0.0:
version "7.0.0"
......@@ -10726,6 +10738,13 @@ vscode-languageserver@^7.0.0:
dependencies:
vscode-languageserver-protocol "3.16.0"
vscode-languageserver@^8.0.0-next.2:
version "8.0.2"
resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-8.0.2.tgz#cfe2f0996d9dfd40d3854e786b2821604dfec06d"
integrity sha512-bpEt2ggPxKzsAOZlXmCJ50bV7VrxwCS5BI4+egUmure/oI/t4OlFzi/YNtVvY24A2UDOZAgwFGgnZPwqSJubkA==
dependencies:
vscode-languageserver-protocol "3.17.2"
vscode-uri@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-2.1.2.tgz#c8d40de93eb57af31f3c715dd650e2ca2c096f1c"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment