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
153
Issues
153
List
Board
Labels
Milestones
Merge Requests
9
Merge Requests
9
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
f260dc7b
Commit
f260dc7b
authored
Jul 01, 2022
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[nodeStory] saver db implementation, does not compile yet
parent
5d2c5e8e
Pipeline
#2972
failed with stage
in 30 minutes and 22 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
20 deletions
+44
-20
gargantext.cabal
gargantext.cabal
+1
-0
package.yaml
package.yaml
+1
-0
NodeStory.hs
src/Gargantext/Database/NodeStory.hs
+42
-20
No files found.
gargantext.cabal
View file @
f260dc7b
...
...
@@ -410,6 +410,7 @@ library
, jose
, json-stream
, lens
, lifted-base
, listsafe
, located-base
, logging-effect
...
...
package.yaml
View file @
f260dc7b
...
...
@@ -195,6 +195,7 @@ library:
-
jose
-
json-stream
-
lens
-
lifted-base
-
listsafe
-
located-base
-
logging-effect
...
...
src/Gargantext/Database/NodeStory.hs
View file @
f260dc7b
...
...
@@ -4,15 +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.Concurrent
.MVar.Lifted
(
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
(
..
),
Node
StoryEnv
(
..
),
Node
ListStory
,
NgramsState
'
,
NgramsStatePatch
'
)
import
Gargantext.Core.NodeStory
(
Archive
(
..
),
NodeStory
(
..
),
NodeListStory
,
NgramsState
'
,
NgramsStatePatch
'
)
import
qualified
Gargantext.Core.NodeStory
as
NS
import
Gargantext.Core.Types
(
NodeId
(
..
),
NodeType
(
..
))
import
Gargantext.Database.Prelude
(
Cmd
,
mkCmd
,
runOpaQuery
)
...
...
@@ -131,33 +131,55 @@ migrateFromDir = do
False
->
pure
0
True
->
upsertNodeArchive
nId
a
)
$
Map
.
toList
nls
_
<-
nodeStoryIncs
(
Just
$
NodeStory
nls
)
listIds
--
_
<-
nodeStoryIncs
(
Just
$
NodeStory
nls
)
listIds
pure
()
------------------------------------
nodeStoryEnv
::
IO
NodeStoryEnv
data
NodeStoryEnv
err
=
NodeStoryEnv
{
_nse_var
::
!
(
MVar
NodeListStory
)
,
_nse_saver
::
!
(
Cmd
err
()
)
,
_nse_getter
::
[
NodeId
]
->
Cmd
err
(
MVar
NodeListStory
)
--, _nse_cleaner :: !(IO ()) -- every 12 hours: cleans the repos of unused NodeStories
-- , _nse_lock :: !FileLock -- TODO (it depends on the option: if with database or file only)
}
--deriving (Generic)
nodeStoryEnv
::
Cmd
err
(
NodeStoryEnv
err
)
nodeStoryEnv
=
do
mvar
<-
nodeStoryVar
Nothing
[]
saver
<-
mkNodeStorySaver
mvar
--saver <- mkNodeStorySaver mvar
let
saver
=
mkNodeStorySaver
mvar
-- let saver = modifyMVar_ mvar $ \mv' -> do
-- writeNodeStories mv'
-- return mv'
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
)
nodeStoryVar
::
Maybe
(
MVar
NodeListStory
)
->
[
NodeId
]
->
Cmd
err
(
MVar
NodeListStory
)
nodeStoryVar
Nothing
nIds
=
do
state
<-
nodeStoryIncs
Nothing
nIds
newMVar
state
nodeStoryVar
(
Just
mv
)
nIds
=
do
_
<-
modifyMVar_
mv
$
\
nsl
->
(
nodeStoryIncs
(
Just
nsl
)
nIds
)
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
)
-- TODO No debounce since this is IO stuff.
-- debounce is useful since it could delay the saving to some later
-- time, asynchronously and we keep operating on memory only.
mkNodeStorySaver
::
MVar
NodeListStory
->
Cmd
err
()
mkNodeStorySaver
mvns
=
withMVar
mvns
writeNodeStories
-- mkNodeStorySaver :: MVar NodeListStory -> Cmd err (Cmd err ())
-- mkNodeStorySaver mvns = mkDebounce settings
-- where
-- settings = defaultDebounceSettings
-- { debounceAction = withMVar mvns (\ns -> writeNodeStories ns)
-- , 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