Commit ba3cd903 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[temp] some debugging code for the tree reload fix

parent 5c21a2b8
...@@ -21,11 +21,13 @@ services: ...@@ -21,11 +21,13 @@ services:
ports: ports:
- 8081:80 - 8081:80
environment: environment:
PGADMIN_DEFAULT_EMAIL: admin PGADMIN_DEFAULT_EMAIL: admin@localhost
PGADMIN_DEFAULT_PASSWORD: admin PGADMIN_DEFAULT_PASSWORD: admin
depends_on: depends_on:
- postgres - postgres
links:
- postgres
corenlp: corenlp:
image: 'cgenie/corenlp-garg' image: 'cgenie/corenlp-garg'
......
...@@ -39,7 +39,7 @@ import Control.Lens (view, toListOf, at, each, _Just, to, set, makeLenses) ...@@ -39,7 +39,7 @@ import Control.Lens (view, toListOf, at, each, _Just, to, set, makeLenses)
import Control.Monad.Error.Class (MonadError()) import Control.Monad.Error.Class (MonadError())
import Data.List (tail, concat, nub) import Data.List (tail, concat, nub)
import Data.Map (Map, fromListWith, lookup) import Data.Map (Map, fromListWith, lookup)
import qualified Data.Set as Set -- import qualified Data.Set as Set
import qualified Data.List as List import qualified Data.List as List
import Data.Text (Text) import Data.Text (Text)
import Database.PostgreSQL.Simple import Database.PostgreSQL.Simple
...@@ -99,9 +99,13 @@ tree_advanced :: HasTreeError err ...@@ -99,9 +99,13 @@ tree_advanced :: HasTreeError err
-> [NodeType] -> [NodeType]
-> Cmd err (Tree NodeTree) -> Cmd err (Tree NodeTree)
tree_advanced r nodeTypes = do tree_advanced r nodeTypes = do
let rPrefix s = "[tree_advanced] root = " <> show r <> " " <> s
mainRoot <- findNodes r Private nodeTypes mainRoot <- findNodes r Private nodeTypes
sharedRoots <- findNodes r Shared nodeTypes printDebug (rPrefix "mainRoot") mainRoot
publicRoots <- findNodes r Public nodeTypes publicRoots <- findNodes r Public nodeTypes
printDebug (rPrefix "publicRoots") publicRoots
sharedRoots <- findNodes r Shared nodeTypes
printDebug (rPrefix "sharedRoots") sharedRoots
toTree $ toTreeParent (mainRoot <> sharedRoots <> publicRoots) toTree $ toTreeParent (mainRoot <> sharedRoots <> publicRoots)
-- | Fetch only first level of tree -- | Fetch only first level of tree
...@@ -110,10 +114,16 @@ tree_first_level :: HasTreeError err ...@@ -110,10 +114,16 @@ tree_first_level :: HasTreeError err
-> [NodeType] -> [NodeType]
-> Cmd err (Tree NodeTree) -> Cmd err (Tree NodeTree)
tree_first_level r nodeTypes = do tree_first_level r nodeTypes = do
let rPrefix s = "[tree_first_level] root = " <> show r <> " " <> s
mainRoot <- findNodes r Private nodeTypes mainRoot <- findNodes r Private nodeTypes
sharedRoots <- findNodes r Shared nodeTypes printDebug (rPrefix "mainRoot") mainRoot
publicRoots <- findNodes r Public nodeTypes publicRoots <- findNodes r Public nodeTypes
toTree $ toSubtreeParent (mainRoot <> sharedRoots <> publicRoots) printDebug (rPrefix "publicRoots") publicRoots
sharedRoots <- findNodes r Shared nodeTypes
printDebug (rPrefix "sharedRoots") sharedRoots
ret <- toTree $ toSubtreeParent r (mainRoot <> sharedRoots <> publicRoots)
printDebug (rPrefix "tree") ret
pure ret
------------------------------------------------------------------------ ------------------------------------------------------------------------
data NodeMode = Private | Shared | Public data NodeMode = Private | Shared | Public
...@@ -214,24 +224,43 @@ toTreeParent :: [DbTreeNode] ...@@ -214,24 +224,43 @@ toTreeParent :: [DbTreeNode]
-> Map (Maybe ParentId) [DbTreeNode] -> Map (Maybe ParentId) [DbTreeNode]
toTreeParent = fromListWith (\a b -> nub $ a <> b) . map (\n -> (_dt_parentId n, [n])) toTreeParent = fromListWith (\a b -> nub $ a <> b) . map (\n -> (_dt_parentId n, [n]))
------------------------------------------------------------------------ ------------------------------------------------------------------------
toSubtreeParent :: [DbTreeNode] -- toSubtreeParent' :: [DbTreeNode]
-- -> Map (Maybe ParentId) [DbTreeNode]
-- toSubtreeParent' ns = fromListWith (\a b -> nub $ a <> b) . map (\n -> (_dt_parentId n, [n])) $ nullifiedParents
-- where
-- nodeIds = Set.fromList $ map (\n -> unNodeId $ _dt_nodeId n) ns
-- nullifiedParents = map nullifyParent ns
-- nullifyParent dt@(DbTreeNode { _dt_parentId = Nothing }) = dt
-- nullifyParent dt@(DbTreeNode { _dt_nodeId = nId
-- , _dt_parentId = Just pId
-- , _dt_typeId = tId
-- , _dt_name = name }) =
-- if Set.member (unNodeId pId) nodeIds then
-- dt
-- else
-- DbTreeNode { _dt_nodeId = nId
-- , _dt_typeId = tId
-- , _dt_parentId = Nothing
-- , _dt_name = name }
------------------------------------------------------------------------
toSubtreeParent :: RootId
-> [DbTreeNode]
-> Map (Maybe ParentId) [DbTreeNode] -> Map (Maybe ParentId) [DbTreeNode]
toSubtreeParent ns = fromListWith (\a b -> nub $ a <> b) . map (\n -> (_dt_parentId n, [n])) $ nullifiedParents toSubtreeParent r ns = fromListWith (\a b -> nub $ a <> b) . map (\n -> (_dt_parentId n, [n])) $ nullifiedParents
where where
nodeIds = Set.fromList $ map (\n -> unNodeId $ _dt_nodeId n) ns
nullifiedParents = map nullifyParent ns nullifiedParents = map nullifyParent ns
nullifyParent dt@(DbTreeNode { _dt_parentId = Nothing }) = dt nullifyParent dt@(DbTreeNode { _dt_parentId = Nothing }) = dt
nullifyParent dt@(DbTreeNode { _dt_nodeId = nId nullifyParent dt@(DbTreeNode { _dt_nodeId = nId
, _dt_parentId = Just pId , _dt_parentId = _pId
, _dt_typeId = tId , _dt_typeId = tId
, _dt_name = name }) = , _dt_name = name }) =
if Set.member (unNodeId pId) nodeIds then if r == nId then
dt
else
DbTreeNode { _dt_nodeId = nId DbTreeNode { _dt_nodeId = nId
, _dt_typeId = tId , _dt_typeId = tId
, _dt_parentId = Nothing , _dt_parentId = Nothing
, _dt_name = name } , _dt_name = name }
else
dt
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | Main DB Tree function -- | Main DB Tree function
dbTree :: RootId dbTree :: RootId
......
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