Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
148
Issues
148
List
Board
Labels
Milestones
Merge Requests
11
Merge Requests
11
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
a9000891
Commit
a9000891
authored
Jun 30, 2022
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[nodeStory] draft implementation of NodeStoryEnv
parent
3201246d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
9 deletions
+39
-9
NodeStory.hs
src/Gargantext/Core/NodeStory.hs
+2
-2
NodeStory.hs
src/Gargantext/Database/NodeStory.hs
+37
-7
No files found.
src/Gargantext/Core/NodeStory.hs
View file @
a9000891
...
...
@@ -83,7 +83,7 @@ class HasNodeStorySaver env where
------------------------------------------------------------------------
readNodeStoryEnv
::
NodeStoryDir
->
IO
NodeStoryEnv
readNodeStoryEnv
nsd
=
do
mvar
<-
nodeStoryVar
nsd
Nothing
[
0
]
mvar
<-
nodeStoryVar
nsd
Nothing
[]
saver
<-
mkNodeStorySaver
nsd
mvar
pure
$
NodeStoryEnv
{
_nse_var
=
mvar
,
_nse_saver
=
saver
...
...
@@ -125,7 +125,7 @@ nodeStoryIncs :: NodeStoryDir
->
Maybe
NodeListStory
->
[
NodeId
]
->
IO
NodeListStory
nodeStoryIncs
_
Nothing
[]
=
p
anic
"nodeStoryIncs: Empty"
nodeStoryIncs
_
Nothing
[]
=
p
ure
$
NodeStory
$
Map
.
empty
nodeStoryIncs
nsd
(
Just
nls
)
ns
=
foldM
(
\
m
n
->
nodeStoryInc
nsd
(
Just
m
)
n
)
nls
ns
nodeStoryIncs
nsd
Nothing
(
ni
:
ns
)
=
do
m
<-
nodeStoryRead
nsd
ni
...
...
src/Gargantext/Database/NodeStory.hs
View file @
a9000891
...
...
@@ -4,13 +4,15 @@
module
Gargantext.Database.NodeStory
where
import
Control.Arrow
(
returnA
)
import
Control.Concurrent
(
MVar
(),
withMVar
,
newMVar
,
modifyMVar_
)
import
Control.Debounce
(
mkDebounce
,
defaultDebounceSettings
,
debounceFreq
,
debounceAction
)
import
Control.Monad
(
foldM
)
import
qualified
Data.Map.Strict
as
Map
import
Data.Profunctor.Product.TH
(
makeAdaptorAndInstance
)
import
Gargantext.API.Ngrams.Tools
(
getRepo
)
import
Gargantext.Core
(
HasDBid
)
import
Gargantext.Core.Mail.Types
(
HasMail
)
import
Gargantext.Core.NodeStory
(
Archive
(
..
),
NodeStory
(
..
),
NodeListStory
,
NgramsState
'
,
NgramsStatePatch
'
)
import
Gargantext.Core.NodeStory
(
Archive
(
..
),
NodeStory
(
..
),
Node
StoryEnv
(
..
),
Node
ListStory
,
NgramsState
'
,
NgramsStatePatch
'
)
import
qualified
Gargantext.Core.NodeStory
as
NS
import
Gargantext.Core.Types
(
NodeId
(
..
),
NodeType
(
..
))
import
Gargantext.Database.Prelude
(
Cmd
,
mkCmd
,
runOpaQuery
)
...
...
@@ -84,6 +86,11 @@ upsertNodeArchive nId a = do
case
Map
.
lookup
nId
m
of
Nothing
->
insertNodeArchive
nId
a
Just
_
->
updateNodeArchive
nId
a
writeNodeStories
::
NodeListStory
->
Cmd
err
()
writeNodeStories
(
NodeStory
nls
)
=
do
_
<-
mapM
(
\
(
nId
,
a
)
->
upsertNodeArchive
nId
a
)
$
Map
.
toList
nls
pure
()
-- | Returns a `NodeListStory`, updating the given one for given `NodeId`
nodeStoryInc
::
Maybe
NodeListStory
->
NodeId
->
Cmd
err
NodeListStory
...
...
@@ -96,7 +103,7 @@ nodeStoryInc (Just ns@(NodeStory nls)) nId = do
Just
_
->
pure
ns
nodeStoryIncs
::
Maybe
NodeListStory
->
[
NodeId
]
->
Cmd
err
NodeListStory
nodeStoryIncs
Nothing
[]
=
p
anic
"nodeStoryIncs: Empty"
nodeStoryIncs
Nothing
[]
=
p
ure
$
NodeStory
$
Map
.
empty
nodeStoryIncs
(
Just
nls
)
ns
=
foldM
(
\
m
n
->
nodeStoryInc
(
Just
m
)
n
)
nls
ns
nodeStoryIncs
Nothing
(
ni
:
ns
)
=
do
m
<-
getNodeStory
ni
...
...
@@ -113,11 +120,6 @@ nodeStoryDec ns@(NodeStory nls) ni = do
_
<-
nodeStoryRemove
ni
pure
$
NodeStory
ns'
-- TODO
-- readNodeStoryEnv
-- getRepo from G.A.N.Tools
migrateFromDir
::
(
HasMail
env
,
HasNodeError
err
,
NS
.
HasNodeStory
env
err
m
,
HasDBid
NodeType
)
=>
m
()
migrateFromDir
=
do
...
...
@@ -131,3 +133,31 @@ migrateFromDir = do
)
$
Map
.
toList
nls
_
<-
nodeStoryIncs
(
Just
$
NodeStory
nls
)
listIds
pure
()
------------------------------------
nodeStoryEnv
::
IO
NodeStoryEnv
nodeStoryEnv
=
do
mvar
<-
nodeStoryVar
Nothing
[]
saver
<-
mkNodeStorySaver
mvar
pure
$
NodeStoryEnv
{
_nse_var
=
mvar
,
_nse_saver
=
saver
,
_nse_getter
=
nodeStoryVar
(
Just
mvar
)
}
nodeStoryVar
::
Maybe
(
MVar
NodeListStory
)
->
[
NodeId
]
->
IO
(
MVar
NodeListStory
)
nodeStoryVar
Nothing
nis
=
(
liftBase
$
nodeStoryIncs
Nothing
nis
)
>>=
newMVar
nodeStoryVar
(
Just
mv
)
nis
=
do
_
<-
modifyMVar_
mv
$
\
mv'
->
(
liftBase
$
nodeStoryIncs
(
Just
mv'
)
nis
)
pure
mv
mkNodeStorySaver
::
MVar
NodeListStory
->
IO
(
IO
()
)
mkNodeStorySaver
mvns
=
mkDebounce
settings
where
settings
=
defaultDebounceSettings
{
debounceAction
=
withMVar
mvns
(
liftBase
$
writeNodeStories
)
,
debounceFreq
=
1
*
minute
-- , debounceEdge = trailingEdge -- Trigger on the trailing edge
}
minute
=
60
*
second
second
=
10
^
(
6
::
Int
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment