Commit 5859a1e1 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FIX] Graph concurrency.

parent f5af4e33
Pipeline #758 failed with stage
...@@ -123,7 +123,10 @@ filterTerms patterns (y,d) = (y,termsInText patterns d) ...@@ -123,7 +123,10 @@ filterTerms patterns (y,d) = (y,termsInText patterns d)
where where
-------------------------------------- --------------------------------------
termsInText :: Patterns -> Text -> [Text] termsInText :: Patterns -> Text -> [Text]
termsInText pats txt = DL.nub $ DL.concat $ map (map unwords) $ extractTermsWithList pats txt termsInText pats txt = DL.nub
$ DL.concat
$ map (map unwords)
$ extractTermsWithList pats txt
-------------------------------------- --------------------------------------
......
...@@ -47,80 +47,56 @@ Pouillard (who mainly made it). ...@@ -47,80 +47,56 @@ Pouillard (who mainly made it).
module Gargantext.API module Gargantext.API
where where
--------------------------------------------------------------------- ---------------------------------------------------------------------
import Control.Concurrent (threadDelay)
import System.IO (FilePath) import Control.Exception (finally)
import Control.Lens
import GHC.Generics (D1, Meta (..), Rep) import Control.Monad.Except (withExceptT, ExceptT)
import GHC.TypeLits (AppendSymbol, Symbol) import Control.Monad.IO.Class (liftIO)
import Control.Monad.Reader (ReaderT, runReaderT)
import Control.Lens import Data.Aeson.Encode.Pretty (encodePretty)
import Control.Exception (finally) import Data.Swagger
import Control.Monad.Except (withExceptT, ExceptT) import Data.Text (Text)
import Control.Monad.IO.Class (liftIO) import Data.Validity
import Control.Monad.Reader (ReaderT, runReaderT) import GHC.Generics (D1, Meta (..), Rep)
import Data.Aeson.Encode.Pretty (encodePretty) import GHC.TypeLits (AppendSymbol, Symbol)
import qualified Data.ByteString.Lazy.Char8 as BL8 import Network.Wai
import Data.Swagger import Network.Wai.Handler.Warp hiding (defaultSettings)
import Data.Text (Text) import Servant
import qualified Data.Text.IO as T import Servant.Auth as SA
--import qualified Data.Set as Set import Servant.Auth.Server (AuthResult(..))
import Data.Validity import Servant.Auth.Swagger ()
import Servant.Job.Async
import Network.Wai import Servant.Swagger
import Network.Wai.Handler.Warp hiding (defaultSettings) import Servant.Swagger.UI
import System.IO (FilePath)
import Servant import Data.List (lookup)
import Servant.Auth as SA import Data.Text.Encoding (encodeUtf8)
import Servant.Auth.Server (AuthResult(..)) import GHC.Base (Applicative)
import Servant.Auth.Swagger ()
--import Servant.Mock (mock)
--import Servant.Job.Server (WithCallbacks)
import Servant.Job.Async
import Servant.Swagger
import Servant.Swagger.UI
-- import Servant.API.Stream
--import Gargantext.API.Swagger
import Gargantext.Database.Node.Contact (HyperdataContact)
import Gargantext.API.Auth (AuthRequest, AuthResponse, AuthenticatedUser(..), AuthContext, auth, withAccess, PathId(..)) import Gargantext.API.Auth (AuthRequest, AuthResponse, AuthenticatedUser(..), AuthContext, auth, withAccess, PathId(..))
import Gargantext.API.Count ( CountAPI, count, Query) import Gargantext.API.Count ( CountAPI, count, Query)
import Gargantext.API.FrontEnd (FrontEndAPI, frontEndServer) import Gargantext.API.FrontEnd (FrontEndAPI, frontEndServer)
import Gargantext.API.Ngrams (HasRepo(..), HasRepoSaver(..), saveRepo, TableNgramsApi, apiNgramsTableDoc) import Gargantext.API.Ngrams (HasRepo(..), HasRepoSaver(..), saveRepo, TableNgramsApi, apiNgramsTableDoc)
import Gargantext.API.Node import Gargantext.API.Node
import Gargantext.API.Orchestrator.Types
import Gargantext.API.Search (SearchPairsAPI, searchPairs) import Gargantext.API.Search (SearchPairsAPI, searchPairs)
import Gargantext.API.Settings
import Gargantext.API.Types import Gargantext.API.Types
import qualified Gargantext.API.Annuaire as Annuaire import Gargantext.Database.Node.Contact (HyperdataContact)
import qualified Gargantext.API.Export as Export
import qualified Gargantext.API.Ngrams.List as List
import qualified Gargantext.API.Corpus.New as New
import Gargantext.Database.Types.Node import Gargantext.Database.Types.Node
import Gargantext.Database.Types.Node (NodeId, CorpusId, AnnuaireId) import Gargantext.Database.Types.Node (NodeId, CorpusId, AnnuaireId)
import Gargantext.Database.Utils (HasConnection) import Gargantext.Database.Utils (HasConnection)
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Viz.Graph.API import Gargantext.Viz.Graph.API
import Network.HTTP.Types hiding (Query)
--import Gargantext.API.Orchestrator
import Gargantext.API.Orchestrator.Types
---------------------------------------------------------------------
import GHC.Base (Applicative)
-- import Control.Lens
import Data.List (lookup)
import Data.Text.Encoding (encodeUtf8)
--import Network.Wai (Request, requestHeaders, responseLBS)
import Network.Wai (Request, requestHeaders) import Network.Wai (Request, requestHeaders)
--import qualified Network.Wai.Handler.Warp as Warp
import Network.Wai.Middleware.Cors import Network.Wai.Middleware.Cors
import Network.Wai.Middleware.RequestLogger import Network.Wai.Middleware.RequestLogger
-- import qualified Network.Wai.Middleware.RequestLogger as RequestLogger import qualified Data.ByteString.Lazy.Char8 as BL8
import qualified Data.Text.IO as T
import Network.HTTP.Types hiding (Query) import qualified Gargantext.API.Annuaire as Annuaire
import qualified Gargantext.API.Corpus.New as New
import Gargantext.API.Settings import qualified Gargantext.API.Export as Export
import qualified Gargantext.API.Ngrams.List as List
showAsServantErr :: GargError -> ServerError showAsServantErr :: GargError -> ServerError
showAsServantErr (GargServerError err) = err showAsServantErr (GargServerError err) = err
...@@ -243,10 +219,14 @@ type GargAdminAPI ...@@ -243,10 +219,14 @@ type GargAdminAPI
---------------------------------------- ----------------------------------------
-- For Tests -- For Tests
type FibAPI = Get '[JSON] Int type WaitAPI = Get '[JSON] Text
fibAPI :: Int -> GargServer FibAPI waitAPI :: Int -> GargServer WaitAPI
fibAPI n = pure (fib n) waitAPI n = do
let
m = (10 :: Int) ^ (6 :: Int)
_ <- liftIO $ threadDelay ( m * n)
pure $ "Waited: " <> (cs $ show n)
---------------------------------------- ----------------------------------------
...@@ -320,9 +300,9 @@ type GargPrivateAPI' = ...@@ -320,9 +300,9 @@ type GargPrivateAPI' =
:> Capture "listId" ListId :> Capture "listId" ListId
:> List.API :> List.API
:<|> "fib" :> Summary "Fib test" :<|> "wait" :> Summary "Wait test"
:> Capture "x" Int :> Capture "x" Int
:> FibAPI -- Get '[JSON] Int :> WaitAPI -- Get '[JSON] Int
-- /mv/<id>/<id> -- /mv/<id>/<id>
-- /merge/<id>/<id> -- /merge/<id>/<id>
...@@ -411,7 +391,7 @@ serverPrivateGargAPI' (AuthenticatedUser (NodeId uid)) ...@@ -411,7 +391,7 @@ serverPrivateGargAPI' (AuthenticatedUser (NodeId uid))
-- :<|> New.api uid -- TODO-SECURITY -- :<|> New.api uid -- TODO-SECURITY
-- :<|> New.info uid -- TODO-SECURITY -- :<|> New.info uid -- TODO-SECURITY
:<|> List.api :<|> List.api
:<|> fibAPI :<|> waitAPI
{- {-
......
...@@ -789,11 +789,11 @@ instance HasRepoVar RepoEnv where ...@@ -789,11 +789,11 @@ instance HasRepoVar RepoEnv where
instance HasRepoSaver RepoEnv where instance HasRepoSaver RepoEnv where
repoSaver = renv_saver repoSaver = renv_saver
type RepoCmdM env err m = type RepoCmdM env err m =
( MonadReader env m ( MonadReader env m
, MonadError err m , MonadError err m
, MonadIO m , MonadIO m
, HasRepo env , HasRepo env
) )
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -1216,12 +1216,9 @@ listNgramsChangedSince listId ngramsType version ...@@ -1216,12 +1216,9 @@ listNgramsChangedSince listId ngramsType version
| otherwise = | otherwise =
tableNgramsPull listId ngramsType version & mapped . v_data %~ (== mempty) tableNgramsPull listId ngramsType version & mapped . v_data %~ (== mempty)
-- Instances -- Instances
instance Arbitrary NgramsRepoElement where instance Arbitrary NgramsRepoElement where
arbitrary = elements $ map ngramsElementToRepo ns arbitrary = elements $ map ngramsElementToRepo ns
where where
NgramsTable ns = mockTable NgramsTable ns = mockTable
...@@ -46,6 +46,7 @@ get lId = fromList ...@@ -46,6 +46,7 @@ get lId = fromList
<$> zip ngramsTypes <$> zip ngramsTypes
<$> mapM (getNgramsTableMap lId) ngramsTypes <$> mapM (getNgramsTableMap lId) ngramsTypes
-- TODO : purge list
put :: FlowCmdM env err m put :: FlowCmdM env err m
=> ListId => ListId
-> NgramsList -> NgramsList
...@@ -53,5 +54,7 @@ put :: FlowCmdM env err m ...@@ -53,5 +54,7 @@ put :: FlowCmdM env err m
put l m = do put l m = do
-- TODO check with Version for optim -- TODO check with Version for optim
_ <- mapM (\(nt, Versioned _v ns) -> putListNgrams' l nt ns) $ toList m _ <- mapM (\(nt, Versioned _v ns) -> putListNgrams' l nt ns) $ toList m
-- TODO reindex
pure True pure True
...@@ -10,6 +10,7 @@ Portability : POSIX ...@@ -10,6 +10,7 @@ Portability : POSIX
-} -}
{-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RankNTypes #-} {-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ConstrainedClassMethods #-} {-# LANGUAGE ConstrainedClassMethods #-}
...@@ -18,8 +19,10 @@ module Gargantext.Core.Flow.Types where ...@@ -18,8 +19,10 @@ module Gargantext.Core.Flow.Types where
import Control.Lens (Lens') import Control.Lens (Lens')
import Data.Map (Map) import Data.Map (Map)
import Data.Text (Text) import Data.Text (Text)
import Data.Maybe (Maybe)
import Gargantext.Text.Terms (TermType) import Gargantext.Text.Terms (TermType)
import Gargantext.Core (Lang) import Gargantext.Core (Lang)
import Gargantext.Prelude
import Gargantext.Database.Schema.Ngrams (Ngrams, NgramsType) import Gargantext.Database.Schema.Ngrams (Ngrams, NgramsType)
import Gargantext.Core.Types.Main (HashId) import Gargantext.Core.Types.Main (HashId)
import Gargantext.Database.Types.Node -- (HyperdataDocument(..)) import Gargantext.Database.Types.Node -- (HyperdataDocument(..))
......
...@@ -17,18 +17,15 @@ commentary with @some markup@. ...@@ -17,18 +17,15 @@ commentary with @some markup@.
module Gargantext.Text.Terms.WithList where module Gargantext.Text.Terms.WithList where
import qualified Data.Algorithms.KMP as KMP import Data.List (null, concatMap)
import Data.Ord
import Data.Text (Text, concat) import Data.Text (Text, concat)
import qualified Data.IntMap.Strict as IntMap import Gargantext.Prelude
import Gargantext.Text.Context import Gargantext.Text.Context
import Gargantext.Text.Terms.Mono (monoTextsBySentence) import Gargantext.Text.Terms.Mono (monoTextsBySentence)
import Prelude (error) import Prelude (error)
import Gargantext.Prelude import qualified Data.Algorithms.KMP as KMP
import Data.List (null, concatMap) import qualified Data.IntMap.Strict as IntMap
import Data.Ord
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -40,7 +37,6 @@ data Pattern = Pattern ...@@ -40,7 +37,6 @@ data Pattern = Pattern
type Patterns = [Pattern] type Patterns = [Pattern]
------------------------------------------------------------------------ ------------------------------------------------------------------------
replaceTerms :: Patterns -> [Text] -> [[Text]] replaceTerms :: Patterns -> [Text] -> [[Text]]
replaceTerms pats terms = go 0 replaceTerms pats terms = go 0
where where
...@@ -81,6 +77,25 @@ extractTermsWithList pats = map (replaceTerms pats) . monoTextsBySentence ...@@ -81,6 +77,25 @@ extractTermsWithList pats = map (replaceTerms pats) . monoTextsBySentence
-- extractTermsWithList' (buildPatterns termList) "Le chat blanc"["chat blanc"] -- extractTermsWithList' (buildPatterns termList) "Le chat blanc"["chat blanc"]
-- ["chat blanc"] -- ["chat blanc"]
extractTermsWithList' :: Patterns -> Text -> [Text] extractTermsWithList' :: Patterns -> Text -> [Text]
extractTermsWithList' pats = map (concat . map concat . replaceTerms pats) . monoTextsBySentence extractTermsWithList' pats = map (concat . map concat . replaceTerms pats)
. monoTextsBySentence
filterWith :: TermList
-> (a -> Text)
-> [a]
-> [(a, [Text])]
filterWith termList f xs = filterWith' termList f zip xs
filterWith' :: TermList
-> (a -> Text)
-> ([a] -> [[Text]] -> [b])
-> [a]
-> [b]
filterWith' termList f f' xs = f' xs
$ map (extractTermsWithList' pats)
$ map f xs
where
pats = buildPatterns termList
...@@ -25,6 +25,7 @@ module Gargantext.Viz.Graph.API ...@@ -25,6 +25,7 @@ module Gargantext.Viz.Graph.API
where where
-- import Debug.Trace (trace) -- import Debug.Trace (trace)
import Control.Concurrent -- (forkIO)
import Control.Lens (set, (^.), _Just, (^?)) import Control.Lens (set, (^.), _Just, (^?))
import Control.Monad.IO.Class (liftIO) import Control.Monad.IO.Class (liftIO)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
...@@ -61,9 +62,16 @@ graphAPI u n = getGraph u n ...@@ -61,9 +62,16 @@ graphAPI u n = getGraph u n
:<|> putGraph n :<|> putGraph n
------------------------------------------------------------------------ ------------------------------------------------------------------------
getGraph :: UserId -> NodeId -> GargServer (Get '[JSON] Graph) getGraph :: UserId -> NodeId -> GargServer (Get '[JSON] Graph)
getGraph uId nId = do getGraph u n = do
newGraph <- liftIO newEmptyMVar
g <- getGraph u n
_ <- liftIO $ forkIO $ putMVar newGraph g
g' <- liftIO $ takeMVar newGraph
pure g'
getGraph' :: UserId -> NodeId -> GargNoServer Graph
getGraph' uId nId = do
nodeGraph <- getNodeWith nId HyperdataGraph nodeGraph <- getNodeWith nId HyperdataGraph
let graph = nodeGraph ^. node_hyperdata . hyperdataGraph let graph = nodeGraph ^. node_hyperdata . hyperdataGraph
let listVersion = graph ^? _Just let listVersion = graph ^? _Just
......
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