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
160
Issues
160
List
Board
Labels
Milestones
Merge Requests
14
Merge Requests
14
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
247345a1
Commit
247345a1
authored
Jun 07, 2023
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/551-dev-graphql-contexts-ngrams' into dev-merge
parents
98305607
c4dbca1a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
72 additions
and
68 deletions
+72
-68
Main.hs
bin/gargantext-upgrade/Main.hs
+33
-33
schema.sql
devops/postgres/schema.sql
+15
-15
0.0.6.9.9.4.4.sql
devops/postgres/upgrade/0.0.6.9.9.4.4.sql
+8
-9
Context.hs
src/Gargantext/API/GraphQL/Context.hs
+2
-0
Tools.hs
src/Gargantext/API/Ngrams/Tools.hs
+2
-2
NgramsByContext.hs
src/Gargantext/Database/Action/Metrics/NgramsByContext.hs
+8
-8
NodeContext.hs
src/Gargantext/Database/Query/Table/NodeContext.hs
+4
-1
No files found.
bin/gargantext-upgrade/Main.hs
View file @
247345a1
...
@@ -68,8 +68,8 @@ main = do
...
@@ -68,8 +68,8 @@ main = do
let
_secret
=
_gc_secretkey
cfg
let
_secret
=
_gc_secretkey
cfg
withDevEnv
iniPath
$
\
env
->
do
withDevEnv
iniPath
$
\
env
->
do
_
<-
runCmdDev
env
addIndex
--
_ <- runCmdDev env addIndex
_
<-
runCmdDev
env
refreshIndex
--
_ <- runCmdDev env refreshIndex
___
___
...
@@ -77,34 +77,34 @@ main = do
...
@@ -77,34 +77,34 @@ main = do
___
___
pure
()
pure
()
refreshIndex
::
Cmd''
DevEnv
IOException
()
--
refreshIndex :: Cmd'' DevEnv IOException ()
refreshIndex
=
do
--
refreshIndex = do
_
<-
execPGSQuery
[
sql
|
REFRESH MATERIALIZED VIEW CONCURRENTLY context_node_ngrams_view;
|]
()
--
_ <- execPGSQuery [sql| REFRESH MATERIALIZED VIEW CONCURRENTLY context_node_ngrams_view; |] ()
pure
()
--
pure ()
addIndex
::
Cmd''
DevEnv
IOException
Int64
--
addIndex :: Cmd'' DevEnv IOException Int64
addIndex
=
do
--
addIndex = do
execPGSQuery
query
()
--
execPGSQuery query ()
where
--
where
query
=
[
sql
|
--
query = [sql|
CREATE MATERIALIZED VIEW IF NOT EXISTS context_node_ngrams_view AS
--
CREATE MATERIALIZED VIEW IF NOT EXISTS context_node_ngrams_view AS
SELECT DISTINCT context_node_ngrams.context_id, ngrams_id, nodes_contexts.node_id
--
SELECT DISTINCT context_node_ngrams.context_id, ngrams_id, nodes_contexts.node_id
FROM nodes_contexts
--
FROM nodes_contexts
JOIN context_node_ngrams
--
JOIN context_node_ngrams
ON context_node_ngrams.context_id = nodes_contexts.context_id;
--
ON context_node_ngrams.context_id = nodes_contexts.context_id;
CREATE INDEX IF NOT EXISTS context_node_ngrams_context_id_ngrams_id_idx
--
CREATE INDEX IF NOT EXISTS context_node_ngrams_context_id_ngrams_id_idx
ON context_node_ngrams(context_id, ngrams_id);
--
ON context_node_ngrams(context_id, ngrams_id);
CREATE INDEX IF NOT EXISTS context_node_ngrams_view_context_id_idx
--
CREATE INDEX IF NOT EXISTS context_node_ngrams_view_context_id_idx
ON context_node_ngrams_view(context_id);
--
ON context_node_ngrams_view(context_id);
CREATE INDEX IF NOT EXISTS context_node_ngrams_view_ngrams_id_idx
--
CREATE INDEX IF NOT EXISTS context_node_ngrams_view_ngrams_id_idx
ON context_node_ngrams_view(ngrams_id);
--
ON context_node_ngrams_view(ngrams_id);
CREATE INDEX IF NOT EXISTS context_node_ngrams_view_node_id_idx
--
CREATE INDEX IF NOT EXISTS context_node_ngrams_view_node_id_idx
ON context_node_ngrams_view(node_id);
--
ON context_node_ngrams_view(node_id);
CREATE UNIQUE INDEX IF NOT EXISTS context_node_ngrams_view_context_ngrams_node_uniq_idx
--
CREATE UNIQUE INDEX IF NOT EXISTS context_node_ngrams_view_context_ngrams_node_uniq_idx
ON context_node_ngrams_view (context_id, ngrams_id, node_id);
--
ON context_node_ngrams_view (context_id, ngrams_id, node_id);
CREATE INDEX IF NOT EXISTS node_stories_ngrams_id_idx
--
CREATE INDEX IF NOT EXISTS node_stories_ngrams_id_idx
ON node_stories(ngrams_id);
--
ON node_stories(ngrams_id);
|]
--
|]
devops/postgres/schema.sql
View file @
247345a1
...
@@ -337,23 +337,23 @@ CREATE OR REPLACE function node_pos(int, int) returns bigint
...
@@ -337,23 +337,23 @@ CREATE OR REPLACE function node_pos(int, int) returns bigint
--create index node_by_pos on nodes using btree(node_pos(id,typename));
--create index node_by_pos on nodes using btree(node_pos(id,typename));
-- Optimization for Ngrams Table View
-- Optimization for Ngrams Table View
CREATE
MATERIALIZED
VIEW
IF
NOT
EXISTS
context_node_ngrams_view
AS
-- CREATE MATERIALIZED VIEW IF NOT EXISTS context_node_ngrams_view AS
SELECT
DISTINCT
context_node_ngrams
.
context_id
,
ngrams_id
,
nodes_contexts
.
node_id
-- SELECT DISTINCT context_node_ngrams.context_id, ngrams_id, nodes_contexts.node_id
FROM
nodes_contexts
-- FROM nodes_contexts
JOIN
context_node_ngrams
-- JOIN context_node_ngrams
ON
context_node_ngrams
.
context_id
=
nodes_contexts
.
context_id
;
-- ON context_node_ngrams.context_id = nodes_contexts.context_id;
-- CREATE INDEX IF NOT EXISTS context_node_ngrams_view_context_id_idx
-- ON context_node_ngrams_view(context_id);
-- CREATE INDEX IF NOT EXISTS context_node_ngrams_view_ngrams_id_idx
-- ON context_node_ngrams_view(ngrams_id);
-- CREATE INDEX IF NOT EXISTS context_node_ngrams_view_node_id_idx
-- ON context_node_ngrams_view(node_id);
-- CREATE UNIQUE INDEX IF NOT EXISTS context_node_ngrams_view_context_ngrams_node_uniq_idx
-- ON context_node_ngrams_view (context_id, ngrams_id, node_id);
CREATE
INDEX
IF
NOT
EXISTS
context_node_ngrams_context_id_ngrams_id_idx
CREATE
INDEX
IF
NOT
EXISTS
context_node_ngrams_context_id_ngrams_id_idx
ON
context_node_ngrams
(
context_id
,
ngrams_id
);
ON
context_node_ngrams
(
context_id
,
ngrams_id
);
CREATE
INDEX
IF
NOT
EXISTS
context_node_ngrams_view_context_id_idx
ON
context_node_ngrams_view
(
context_id
);
CREATE
INDEX
IF
NOT
EXISTS
context_node_ngrams_view_ngrams_id_idx
ON
context_node_ngrams_view
(
ngrams_id
);
CREATE
INDEX
IF
NOT
EXISTS
context_node_ngrams_view_node_id_idx
ON
context_node_ngrams_view
(
node_id
);
CREATE
UNIQUE
INDEX
IF
NOT
EXISTS
context_node_ngrams_view_context_ngrams_node_uniq_idx
ON
context_node_ngrams_view
(
context_id
,
ngrams_id
,
node_id
);
CREATE
INDEX
IF
NOT
EXISTS
node_stories_ngrams_id_idx
CREATE
INDEX
IF
NOT
EXISTS
node_stories_ngrams_id_idx
ON
node_stories
(
ngrams_id
);
ON
node_stories
(
ngrams_id
);
devops/postgres/upgrade/0.0.6.9.9.4.4.sql
View file @
247345a1
-- create materialized view if not exists context_node_ngrams_view as
-- select context_node_ngrams.context_id, ngrams_id, nodes_contexts.node_id
-- from nodes_contexts
-- join context_node_ngrams
-- on context_node_ngrams.context_id = nodes_contexts.context_id;
-- create index if not exists context_node_ngrams_view_context_id_idx on context_node_ngrams_view(context_id);
create
materialized
view
if
not
exists
context_node_ngrams_view
as
-- create index if not exists context_node_ngrams_view_ngrams_id_idx on context_node_ngrams_view(ngrams_id);
select
context_node_ngrams
.
context_id
,
ngrams_id
,
nodes_contexts
.
node_id
-- create index if not exists context_node_ngrams_view_node_id_idx on context_node_ngrams_view(node_id);
from
nodes_contexts
join
context_node_ngrams
on
context_node_ngrams
.
context_id
=
nodes_contexts
.
context_id
;
create
index
if
not
exists
context_node_ngrams_context_id_ngrams_id_idx
on
context_node_ngrams
(
context_id
,
ngrams_id
);
create
index
if
not
exists
context_node_ngrams_context_id_ngrams_id_idx
on
context_node_ngrams
(
context_id
,
ngrams_id
);
create
index
if
not
exists
context_node_ngrams_view_context_id_idx
on
context_node_ngrams_view
(
context_id
);
create
index
if
not
exists
context_node_ngrams_view_ngrams_id_idx
on
context_node_ngrams_view
(
ngrams_id
);
create
index
if
not
exists
context_node_ngrams_view_node_id_idx
on
context_node_ngrams_view
(
node_id
);
create
index
if
not
exists
node_stories_ngrams_id_idx
on
node_stories
(
ngrams_id
);
create
index
if
not
exists
node_stories_ngrams_id_idx
on
node_stories
(
ngrams_id
);
src/Gargantext/API/GraphQL/Context.hs
View file @
247345a1
...
@@ -138,6 +138,7 @@ dbNodeContext context_id node_id = do
...
@@ -138,6 +138,7 @@ dbNodeContext context_id node_id = do
c
<-
lift
$
getNodeContext
(
NodeId
context_id
)
(
NodeId
node_id
)
c
<-
lift
$
getNodeContext
(
NodeId
context_id
)
(
NodeId
node_id
)
pure
$
toNodeContextGQL
<$>
[
c
]
pure
$
toNodeContextGQL
<$>
[
c
]
-- | Returns list of `ContextGQL` for given ngrams in given corpus id.
dbContextForNgrams
dbContextForNgrams
::
(
CmdCommon
env
)
::
(
CmdCommon
env
)
=>
Int
->
[
Text
]
->
GqlM
e
env
[
ContextGQL
]
=>
Int
->
[
Text
]
->
GqlM
e
env
[
ContextGQL
]
...
@@ -146,6 +147,7 @@ dbContextForNgrams node_id ngrams_terms = do
...
@@ -146,6 +147,7 @@ dbContextForNgrams node_id ngrams_terms = do
--lift $ printDebug "[dbContextForNgrams] contextsForNgramsTerms" contextsForNgramsTerms
--lift $ printDebug "[dbContextForNgrams] contextsForNgramsTerms" contextsForNgramsTerms
pure
$
toContextGQL
<$>
contextsForNgramsTerms
pure
$
toContextGQL
<$>
contextsForNgramsTerms
-- | Fetch ngrams matching given context in a given list id.
dbContextNgrams
dbContextNgrams
::
(
CmdCommon
env
)
::
(
CmdCommon
env
)
=>
Int
->
Int
->
GqlM
e
env
[
Text
]
=>
Int
->
Int
->
GqlM
e
env
[
Text
]
...
...
src/Gargantext/API/Ngrams/Tools.hs
View file @
247345a1
...
@@ -138,7 +138,7 @@ filterListWithRootHashMap lt m = snd <$> HM.filter isMapTerm m
...
@@ -138,7 +138,7 @@ filterListWithRootHashMap lt m = snd <$> HM.filter isMapTerm m
isMapTerm
(
l
,
maybeRoot
)
=
case
maybeRoot
of
isMapTerm
(
l
,
maybeRoot
)
=
case
maybeRoot
of
Nothing
->
l
==
lt
Nothing
->
l
==
lt
Just
r
->
case
HM
.
lookup
r
m
of
Just
r
->
case
HM
.
lookup
r
m
of
Nothing
->
panic
$
"[Garg.API.Ngrams.Tools] filter
WithRoot
, unknown key: "
<>
unNgramsTerm
r
Nothing
->
panic
$
"[Garg.API.Ngrams.Tools] filter
ListWithRootHashMap
, unknown key: "
<>
unNgramsTerm
r
Just
(
l'
,
_
)
->
l'
==
lt
Just
(
l'
,
_
)
->
l'
==
lt
filterListWithRoot
::
[
ListType
]
filterListWithRoot
::
[
ListType
]
...
@@ -149,7 +149,7 @@ filterListWithRoot lt m = snd <$> HM.filter isMapTerm m
...
@@ -149,7 +149,7 @@ filterListWithRoot lt m = snd <$> HM.filter isMapTerm m
isMapTerm
(
l
,
maybeRoot
)
=
case
maybeRoot
of
isMapTerm
(
l
,
maybeRoot
)
=
case
maybeRoot
of
Nothing
->
elem
l
lt
Nothing
->
elem
l
lt
Just
r
->
case
HM
.
lookup
r
m
of
Just
r
->
case
HM
.
lookup
r
m
of
Nothing
->
panic
$
"[Garg.API.Ngrams.Tools] filterWithRoot, unknown key: "
<>
unNgramsTerm
r
Nothing
->
panic
$
"[Garg.API.Ngrams.Tools] filter
List
WithRoot, unknown key: "
<>
unNgramsTerm
r
Just
(
l'
,
_
)
->
elem
l'
lt
Just
(
l'
,
_
)
->
elem
l'
lt
groupNodesByNgrams
::
(
At
root_map
groupNodesByNgrams
::
(
At
root_map
...
...
src/Gargantext/Database/Action/Metrics/NgramsByContext.hs
View file @
247345a1
...
@@ -18,7 +18,7 @@ module Gargantext.Database.Action.Metrics.NgramsByContext
...
@@ -18,7 +18,7 @@ module Gargantext.Database.Action.Metrics.NgramsByContext
-- import Debug.Trace (trace)
-- import Debug.Trace (trace)
--import Data.Map.Strict.Patch (PatchMap, Replace, diff)
--import Data.Map.Strict.Patch (PatchMap, Replace, diff)
import
Control.Monad
(
void
)
--
import Control.Monad (void)
import
Data.HashMap.Strict
(
HashMap
)
import
Data.HashMap.Strict
(
HashMap
)
import
Data.Map.Strict
(
Map
)
import
Data.Map.Strict
(
Map
)
import
Data.Set
(
Set
)
import
Data.Set
(
Set
)
...
@@ -30,7 +30,7 @@ import Gargantext.API.Ngrams.Types (NgramsTerm(..))
...
@@ -30,7 +30,7 @@ import Gargantext.API.Ngrams.Types (NgramsTerm(..))
import
Gargantext.Core
import
Gargantext.Core
import
Gargantext.Data.HashMap.Strict.Utils
as
HM
import
Gargantext.Data.HashMap.Strict.Utils
as
HM
import
Gargantext.Database.Admin.Types.Node
(
ListId
,
CorpusId
,
NodeId
(
..
),
ContextId
,
MasterCorpusId
,
NodeType
(
NodeDocument
),
UserCorpusId
,
DocId
)
import
Gargantext.Database.Admin.Types.Node
(
ListId
,
CorpusId
,
NodeId
(
..
),
ContextId
,
MasterCorpusId
,
NodeType
(
NodeDocument
),
UserCorpusId
,
DocId
)
import
Gargantext.Database.Prelude
(
Cmd
,
runPGSQuery
,
execPGSQuery
)
import
Gargantext.Database.Prelude
(
Cmd
,
runPGSQuery
)
--
, execPGSQuery)
import
Gargantext.Database.Schema.Ngrams
(
ngramsTypeId
,
NgramsType
(
..
))
import
Gargantext.Database.Schema.Ngrams
(
ngramsTypeId
,
NgramsType
(
..
))
import
Gargantext.Prelude
import
Gargantext.Prelude
import
qualified
Data.HashMap.Strict
as
HM
import
qualified
Data.HashMap.Strict
as
HM
...
@@ -428,9 +428,9 @@ queryNgramsByContextMaster' = [sql|
...
@@ -428,9 +428,9 @@ queryNgramsByContextMaster' = [sql|
-- - at reindex stage
-- - at reindex stage
-- - at the end of each text flow
-- - at the end of each text flow
refreshNgramsMaterialized
::
Cmd
err
()
--
refreshNgramsMaterialized :: Cmd err ()
refreshNgramsMaterialized
=
void
$
execPGSQuery
refreshNgramsMaterializedQuery
()
--
refreshNgramsMaterialized = void $ execPGSQuery refreshNgramsMaterializedQuery ()
where
--
where
refreshNgramsMaterializedQuery
::
DPS
.
Query
--
refreshNgramsMaterializedQuery :: DPS.Query
refreshNgramsMaterializedQuery
=
--
refreshNgramsMaterializedQuery =
[
sql
|
REFRESH MATERIALIZED VIEW CONCURRENTLY context_node_ngrams_view;
|]
--
[sql| REFRESH MATERIALIZED VIEW CONCURRENTLY context_node_ngrams_view; |]
src/Gargantext/Database/Query/Table/NodeContext.hs
View file @
247345a1
...
@@ -194,7 +194,10 @@ getContextsForNgramsTerms cId ngramsTerms = do
...
@@ -194,7 +194,10 @@ getContextsForNgramsTerms cId ngramsTerms = do
-- | Query the `context_node_ngrams` table and return ngrams for given
-- | Query the `context_node_ngrams` table and return ngrams for given
-- `context_id` and `list_id`.
-- `context_id` and `list_id`.
-- WARNING: `context_node_ngrams` can be outdated.
-- WARNING: `context_node_ngrams` can be outdated. This is because it
-- is expensive to keep all ngrams matching a given context and if
-- someone adds an ngram, we need to recompute its m2m relation to all
-- existing documents.
getContextNgrams
::
HasNodeError
err
getContextNgrams
::
HasNodeError
err
=>
NodeId
=>
NodeId
->
NodeId
->
NodeId
...
...
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