Commit 00960e3a authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[write nodes] use closest corpus as parent

parent 7647ad93
Pipeline #1923 canceled with stage
...@@ -34,7 +34,7 @@ import Gargantext.Database.Action.Flow.Types (FlowCmdM) ...@@ -34,7 +34,7 @@ import Gargantext.Database.Action.Flow.Types (FlowCmdM)
import Gargantext.Database.Admin.Types.Hyperdata.Document (HyperdataDocument(..)) import Gargantext.Database.Admin.Types.Hyperdata.Document (HyperdataDocument(..))
import Gargantext.Database.Admin.Types.Hyperdata.Frame import Gargantext.Database.Admin.Types.Hyperdata.Frame
import Gargantext.Database.Admin.Types.Node import Gargantext.Database.Admin.Types.Node
import Gargantext.Database.Query.Table.Node (getChildrenByType, getNodeWith) import Gargantext.Database.Query.Table.Node (getChildrenByType, getClosestParentIdByType', getNodeWith)
import Gargantext.Database.Schema.Node (node_hyperdata) import Gargantext.Database.Schema.Node (node_hyperdata)
import Gargantext.Prelude import Gargantext.Prelude
import GHC.Generics (Generic) import GHC.Generics (Generic)
...@@ -60,7 +60,6 @@ api uId nId = ...@@ -60,7 +60,6 @@ api uId nId =
JobFunction (\p log'' -> JobFunction (\p log'' ->
let let
log' x = do log' x = do
printDebug "documents from write nodes" x
liftBase $ log'' x liftBase $ log'' x
in documentsFromWriteNodes uId nId p (liftBase . log') in documentsFromWriteNodes uId nId p (liftBase . log')
) )
...@@ -71,7 +70,7 @@ documentsFromWriteNodes :: (HasSettings env, FlowCmdM env err m) ...@@ -71,7 +70,7 @@ documentsFromWriteNodes :: (HasSettings env, FlowCmdM env err m)
-> Params -> Params
-> (JobLog -> m ()) -> (JobLog -> m ())
-> m JobLog -> m JobLog
documentsFromWriteNodes uId nId p logStatus = do documentsFromWriteNodes uId nId _p logStatus = do
logStatus JobLog { _scst_succeeded = Just 1 logStatus JobLog { _scst_succeeded = Just 1
, _scst_failed = Just 0 , _scst_failed = Just 0
...@@ -79,12 +78,10 @@ documentsFromWriteNodes uId nId p logStatus = do ...@@ -79,12 +78,10 @@ documentsFromWriteNodes uId nId p logStatus = do
, _scst_events = Just [] , _scst_events = Just []
} }
_ <- printDebug "[documentsFromWriteNodes] inside job, uId" uId mcId <- getClosestParentIdByType' nId NodeCorpus
_ <- printDebug "[documentsFromWriteNodes] inside job, nId" nId let cId = maybe (panic "[G.A.N.DFWN] Node has no parent") identity mcId
_ <- printDebug "[documentsFromWriteNodes] inside job, p" p
frameWriteIds <- getChildrenByType nId NodeFrameWrite frameWriteIds <- getChildrenByType nId NodeFrameWrite
_ <- printDebug "[documentsFromWriteNodes] children" frameWriteIds
-- https://write.frame.gargantext.org/<frame_id>/download -- https://write.frame.gargantext.org/<frame_id>/download
frameWrites <- mapM (\id -> getNodeWith id (Proxy :: Proxy HyperdataFrame)) frameWriteIds frameWrites <- mapM (\id -> getNodeWith id (Proxy :: Proxy HyperdataFrame)) frameWriteIds
...@@ -94,13 +91,11 @@ documentsFromWriteNodes uId nId p logStatus = do ...@@ -94,13 +91,11 @@ documentsFromWriteNodes uId nId p logStatus = do
contents <- getHyperdataFrameContents (node ^. node_hyperdata) contents <- getHyperdataFrameContents (node ^. node_hyperdata)
pure (node, contents) pure (node, contents)
) frameWrites ) frameWrites
_ <- printDebug "[documentsFromWriteNodes] frameWritesWithContents" frameWritesWithContents
let parsedE = (\(node, contents) -> hyperdataDocumentFromFrameWrite (node ^. node_hyperdata, contents)) <$> frameWritesWithContents let parsedE = (\(node, contents) -> hyperdataDocumentFromFrameWrite (node ^. node_hyperdata, contents)) <$> frameWritesWithContents
let parsed = rights parsedE let parsed = rights parsedE
_ <- printDebug "[documentsFromWriteNodes] parsed" parsed
_ <- flowDataText (RootId (NodeId uId)) (DataNew [parsed]) (Multi EN) nId Nothing _ <- flowDataText (RootId (NodeId uId)) (DataNew [parsed]) (Multi EN) cId Nothing
pure JobLog { _scst_succeeded = Just 2 pure JobLog { _scst_succeeded = Just 2
, _scst_failed = Just 0 , _scst_failed = Just 0
......
...@@ -142,6 +142,29 @@ getClosestParentIdByType nId nType = do ...@@ -142,6 +142,29 @@ getClosestParentIdByType nId nType = do
WHERE n1.id = ? AND 0 = ?; WHERE n1.id = ? AND 0 = ?;
|] |]
-- | Similar to `getClosestParentIdByType` but includes current node
-- in search too
getClosestParentIdByType' :: HasDBid NodeType
=> NodeId
-> NodeType
-> Cmd err (Maybe NodeId)
getClosestParentIdByType' nId nType = do
result <- runPGSQuery query (nId, 0 :: Int)
case result of
[(NodeId id, pTypename)] -> do
if toDBid nType == pTypename then
pure $ Just $ NodeId id
else
getClosestParentIdByType nId nType
_ -> pure Nothing
where
query :: DPS.Query
query = [sql|
SELECT n.id, n.typename
FROM nodes n
WHERE n.id = ? AND 0 = ?;
|]
-- | Given a node id, find all it's children (no matter how deep) of -- | Given a node id, find all it's children (no matter how deep) of
-- given node type. -- given node type.
getChildrenByType :: HasDBid NodeType getChildrenByType :: HasDBid NodeType
......
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