Commit e9db08a1 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[graph update] add "force" parameter to force graph recomputation

Otherwise the "refresh" buttons won't work because list version
doesn't change.
parent 33bf8ea5
...@@ -36,7 +36,7 @@ import Gargantext.Database.Admin.Types.Node ...@@ -36,7 +36,7 @@ import Gargantext.Database.Admin.Types.Node
import Gargantext.Database.Query.Table.Node (getNode) import Gargantext.Database.Query.Table.Node (getNode)
import Gargantext.Database.Schema.Node (node_parent_id) import Gargantext.Database.Schema.Node (node_parent_id)
import Gargantext.Database.Schema.Ngrams (NgramsType(NgramsTerms)) import Gargantext.Database.Schema.Ngrams (NgramsType(NgramsTerms))
import Gargantext.Prelude (Ord, Eq, (<$>), ($), liftBase, (.), printDebug, pure, show, cs, (<>), panic) import Gargantext.Prelude (Bool(..), Ord, Eq, (<$>), ($), liftBase, (.), printDebug, pure, show, cs, (<>), panic)
import qualified Gargantext.Utils.Aeson as GUA import qualified Gargantext.Utils.Aeson as GUA
import Prelude (Enum, Bounded, minBound, maxBound) import Prelude (Enum, Bounded, minBound, maxBound)
import Servant import Servant
...@@ -95,7 +95,7 @@ updateNode uId nId (UpdateNodeParamsGraph metric) logStatus = do ...@@ -95,7 +95,7 @@ updateNode uId nId (UpdateNodeParamsGraph metric) logStatus = do
, _scst_events = Just [] , _scst_events = Just []
} }
_ <- recomputeGraph uId nId (Just metric) _ <- recomputeGraph uId nId (Just metric) True
pure JobLog { _scst_succeeded = Just 2 pure JobLog { _scst_succeeded = Just 2
, _scst_failed = Just 0 , _scst_failed = Just 0
......
...@@ -120,8 +120,9 @@ recomputeGraph :: FlowCmdM env err m ...@@ -120,8 +120,9 @@ recomputeGraph :: FlowCmdM env err m
=> UserId => UserId
-> NodeId -> NodeId
-> Maybe GraphMetric -> Maybe GraphMetric
-> Bool
-> m Graph -> m Graph
recomputeGraph _uId nId maybeDistance = do recomputeGraph _uId nId maybeDistance force = do
nodeGraph <- getNodeWith nId (Proxy :: Proxy HyperdataGraph) nodeGraph <- getNodeWith nId (Proxy :: Proxy HyperdataGraph)
let let
graph = nodeGraph ^. node_hyperdata . hyperdataGraph graph = nodeGraph ^. node_hyperdata . hyperdataGraph
...@@ -142,21 +143,22 @@ recomputeGraph _uId nId maybeDistance = do ...@@ -142,21 +143,22 @@ recomputeGraph _uId nId maybeDistance = do
repo <- getRepo' [listId] repo <- getRepo' [listId]
let v = repo ^. unNodeStory . at listId . _Just . a_version let v = repo ^. unNodeStory . at listId . _Just . a_version
let computeG mt = do
g <- computeGraph cId similarity NgramsTerms repo
let g' = set graph_metadata mt g
_ <- updateHyperdata nId (HyperdataGraph (Just g') camera)
pure g'
case graph of case graph of
Nothing -> do Nothing -> do
graph' <- computeGraph cId similarity NgramsTerms repo
mt <- defaultGraphMetadata cId "Title" repo (fromMaybe Order1 maybeDistance) mt <- defaultGraphMetadata cId "Title" repo (fromMaybe Order1 maybeDistance)
let graph'' = set graph_metadata (Just mt) graph' g <- computeG $ Just mt
_ <- updateHyperdata nId (HyperdataGraph (Just graph'') camera) pure $ trace "[G.V.G.API.recomputeGraph] Graph empty, computed" g
pure $ trace "[G.V.G.API.recomputeGraph] Graph empty, computed" graph'' Just graph' -> if (listVersion == Just v) && (not force)
Just graph' -> if listVersion == Just v
then pure graph' then pure graph'
else do else do
graph'' <- computeGraph cId similarity NgramsTerms repo g <- computeG graphMetadata
let graph''' = set graph_metadata graphMetadata graph'' pure $ trace "[G.V.G.API] Graph exists, recomputing" g
_ <- updateHyperdata nId (HyperdataGraph (Just graph''') camera)
pure $ trace "[G.V.G.API] Graph exists, recomputing" graph'''
computeGraph :: FlowCmdM env err m computeGraph :: FlowCmdM env err m
...@@ -242,7 +244,7 @@ graphRecompute u n logStatus = do ...@@ -242,7 +244,7 @@ graphRecompute u n logStatus = do
, _scst_remaining = Just 1 , _scst_remaining = Just 1
, _scst_events = Just [] , _scst_events = Just []
} }
_g <- trace (show u) $ recomputeGraph u n Nothing _g <- trace (show u) $ recomputeGraph u n Nothing False
pure JobLog { _scst_succeeded = Just 1 pure JobLog { _scst_succeeded = Just 1
, _scst_failed = Just 0 , _scst_failed = Just 0
, _scst_remaining = Just 0 , _scst_remaining = Just 0
...@@ -297,7 +299,7 @@ recomputeVersions :: FlowCmdM env err m ...@@ -297,7 +299,7 @@ recomputeVersions :: FlowCmdM env err m
=> UserId => UserId
-> NodeId -> NodeId
-> m Graph -> m Graph
recomputeVersions uId nId = recomputeGraph uId nId Nothing recomputeVersions uId nId = recomputeGraph uId nId Nothing False
------------------------------------------------------------ ------------------------------------------------------------
graphClone :: UserId graphClone :: UserId
......
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