Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Christian Merten
purescript-gargantext
Commits
fc60ff0a
Commit
fc60ff0a
authored
Jul 01, 2020
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[docstable] hashed response & caching
parent
51869b8d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
17 deletions
+52
-17
DocsTable.purs
src/Gargantext/Components/DocsTable.purs
+51
-17
Texts.purs
src/Gargantext/Components/Nodes/Texts.purs
+1
-0
No files found.
src/Gargantext/Components/DocsTable.purs
View file @
fc60ff0a
-- TODO: this module should be replaced by FacetsTable
-- TODO: this module should be replaced by FacetsTable
module Gargantext.Components.DocsTable where
module Gargantext.Components.DocsTable where
import Prelude
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject, (.:), (:=), (~>), encodeJson)
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject, (.:), (:=), (~>), encodeJson)
import Data.Array as A
import Data.Array as A
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep (class Generic)
...
@@ -29,15 +28,17 @@ import Effect.Class (liftEffect)
...
@@ -29,15 +28,17 @@ import Effect.Class (liftEffect)
import Reactix as R
import Reactix as R
import Reactix.DOM.HTML as H
import Reactix.DOM.HTML as H
------------------------------------------------------------------------
------------------------------------------------------------------------
import Gargantext.Prelude
import Gargantext.Components.Table as T
import Gargantext.Components.Table as T
import Gargantext.Ends (Frontends, url)
import Gargantext.Ends (Frontends, url)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Hooks.Loader (useLoader
, useLoaderWithCache, HashedResponse(..)
)
import Gargantext.Utils.List (sortWith) as L
import Gargantext.Utils.List (sortWith) as L
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix as R2
import Gargantext.Routes as Routes
import Gargantext.Routes as Routes
import Gargantext.Routes (SessionRoute(NodeAPI))
import Gargantext.Routes (SessionRoute(NodeAPI))
import Gargantext.Sessions (Session, sessionId, get, post, delete, put)
import Gargantext.Sessions (Session, sessionId, get, post, delete, put)
import Gargantext.Types (NodeType(..), OrderBy(..), TabType, TabPostQuery(..), AffTableResult, showTabType')
import Gargantext.Types (NodeType(..), OrderBy(..), Tab
leResult, Tab
Type, TabPostQuery(..), AffTableResult, showTabType')
------------------------------------------------------------------------
------------------------------------------------------------------------
data Category = Trash | UnRead | Checked | Topic | Favorite
data Category = Trash | UnRead | Checked | Topic | Favorite
...
@@ -50,6 +51,10 @@ instance showCategory :: Show Category where
...
@@ -50,6 +51,10 @@ instance showCategory :: Show Category where
show = genericShow
show = genericShow
instance eqCategory :: Eq Category where
instance eqCategory :: Eq Category where
eq = genericEq
eq = genericEq
instance decodeJsonCategory :: DecodeJson Category where
decodeJson json = do
obj <- decodeJson json
pure $ decodeCategory obj
instance encodeJsonCategory :: EncodeJson Category where
instance encodeJsonCategory :: EncodeJson Category where
encodeJson cat = encodeJson (cat2score cat)
encodeJson cat = encodeJson (cat2score cat)
...
@@ -185,19 +190,39 @@ data Action
...
@@ -185,19 +190,39 @@ data Action
newtype DocumentsView
newtype DocumentsView
= DocumentsView
= DocumentsView
{ _id :: Int
{ _id :: Int
, url :: String
, date :: Int
, title :: String
, source :: String
, category :: Category
, category :: Category
, date :: Int
, ngramCount :: Int
, ngramCount :: Int
, source :: String
, title :: String
, url :: String
}
}
derive instance genericDocumentsView :: Generic DocumentsView _
derive instance genericDocumentsView :: Generic DocumentsView _
instance showDocumentsView :: Show DocumentsView where
instance showDocumentsView :: Show DocumentsView where
show = genericShow
show = genericShow
instance decodeDocumentsView :: DecodeJson DocumentsView where
decodeJson json = do
obj <- decodeJson json
_id <- obj .: "id"
category <- obj .: "category"
date <- obj .: "date"
ngramCount <- obj .: "ngramCount"
source <- obj .: "source"
title <- obj .: "title"
url <- obj .: "url"
pure $ DocumentsView { _id, category, date, ngramCount, source, title, url }
instance encodeDocumentsView :: EncodeJson DocumentsView where
encodeJson (DocumentsView dv) =
"id" := dv._id
~> "category" := dv.category
~> "date" := dv.date
~> "ngramCount" := dv.ngramCount
~> "source" := dv.source
~> "title" := dv.title
~> "url" := dv.url
~> jsonEmptyObject
newtype Response = Response
newtype Response = Response
...
@@ -332,19 +357,19 @@ type PageParams =
...
@@ -332,19 +357,19 @@ type PageParams =
, query :: Query
, query :: Query
, params :: T.Params}
, params :: T.Params}
loadPage :: Session -> PageParams -> Aff (
Tuple Int (Array DocumentsView
))
loadPage :: Session -> PageParams -> Aff (
HashedResponse (Tuple Int (Array DocumentsView)
))
loadPage session { corpusId, listId, nodeId, query, tabType } = do
loadPage session { corpusId, listId, nodeId, query, tabType } = do
--liftEffect $ log3 "loading documents page: loadPage with Offset and limit" offset limit
--liftEffect $ log3 "loading documents page: loadPage with Offset and limit" offset limit
-- res <- get $ toUrl endConfigStateful Back (Tab tabType offset limit (convOrderBy <$> orderBy)) (Just nodeId)
-- res <- get $ toUrl endConfigStateful Back (Tab tabType offset limit (convOrderBy <$> orderBy)) (Just nodeId)
let p = NodeAPI Node (Just nodeId) $ "table" <> "?tabType=" <> (showTabType' tabType)
let p = NodeAPI Node (Just nodeId) $ "table" <> "?tabType=" <> (showTabType' tabType)
res <- (get session p) :: AffTableResult Response
HashedResponse { md5, value: res } <- (get session p) :: Aff (HashedResponse (TableResult Response))
let docs = res2corpus <$> res.docs
let docs = res2corpus <$> res.docs
pure $
let ret = if mock then
if mock then
--Tuple 0 (take limit $ drop offset sampleData)
--Tuple 0 (take limit $ drop offset sampleData)
Tuple 0 sampleData
Tuple 0 sampleData
else
else
Tuple res.count docs
Tuple res.count docs
pure $ HashedResponse { md5, value: ret }
where
where
res2corpus :: Response -> DocumentsView
res2corpus :: Response -> DocumentsView
res2corpus (Response r) =
res2corpus (Response r) =
...
@@ -357,6 +382,11 @@ loadPage session { corpusId, listId, nodeId, query, tabType } = do
...
@@ -357,6 +382,11 @@ loadPage session { corpusId, listId, nodeId, query, tabType } = do
, ngramCount : r.ngramCount
, ngramCount : r.ngramCount
}
}
getPageMD5 :: Session -> PageParams -> Aff String
getPageMD5 session { corpusId, listId, nodeId, query, tabType } = do
let p = NodeAPI Node (Just nodeId) $ "table/md5" <> "?tabType=" <> (showTabType' tabType)
(get session p) :: Aff String
convOrderBy (Just (T.ASC (T.ColumnName "Date"))) = Just DateAsc
convOrderBy (Just (T.ASC (T.ColumnName "Date"))) = Just DateAsc
convOrderBy (Just (T.DESC (T.ColumnName "Date"))) = Just DateDesc
convOrderBy (Just (T.DESC (T.ColumnName "Date"))) = Just DateDesc
...
@@ -372,12 +402,16 @@ pageLayout props = R.createElement pageLayoutCpt props []
...
@@ -372,12 +402,16 @@ pageLayout props = R.createElement pageLayoutCpt props []
pageLayoutCpt :: R.Component PageLayoutProps
pageLayoutCpt :: R.Component PageLayoutProps
pageLayoutCpt = R.hooksComponent "G.C.DocsTable.pageLayout" cpt where
pageLayoutCpt = R.hooksComponent "G.C.DocsTable.pageLayout" cpt where
cpt props@{frontends, session, nodeId, listId, corpusId, tabType, query, params} _ =
cpt props@{frontends, session, nodeId, listId, corpusId, tabType, query, params} _ =
useLoader path (loadPage session) paint
-- useLoader path (loadPage session) paint
useLoaderWithCache path keyFunc (getPageMD5 session) (loadPage session) paint
where
where
path = { nodeId, listId, corpusId, tabType, query, params }
path = { nodeId, listId, corpusId, tabType, query, params }
paint (Tuple count docs) = page params (newProps count) docs
paint (Tuple count docs) = page params (newProps count) docs
newProps count = props { totalRecords = count }
newProps count = props { totalRecords = count }
keyFunc { corpusId, listId, nodeId, tabType } =
"page-" <> (show tabType) <> "-" <> (show corpusId) <> "-" <> (show nodeId) <> "-" <> (show listId)
type PageProps = (
type PageProps = (
documents :: Array DocumentsView
documents :: Array DocumentsView
, layout :: Record PageLayoutProps
, layout :: Record PageLayoutProps
...
...
src/Gargantext/Components/Nodes/Texts.purs
View file @
fc60ff0a
...
@@ -16,6 +16,7 @@ import Gargantext.Components.Nodes.Corpus.Chart.Histo (histo)
...
@@ -16,6 +16,7 @@ import Gargantext.Components.Nodes.Corpus.Chart.Histo (histo)
import Gargantext.Components.Nodes.Corpus.Types (CorpusData, Hyperdata(..), getCorpusInfo, CorpusInfo(..))
import Gargantext.Components.Nodes.Corpus.Types (CorpusData, Hyperdata(..), getCorpusInfo, CorpusInfo(..))
import Gargantext.Components.Tab as Tab
import Gargantext.Components.Tab as Tab
import Gargantext.Components.Table as Table
import Gargantext.Components.Table as Table
import Gargantext.Hooks.Loader (useLoaderWithCache)
import Gargantext.Ends (Frontends)
import Gargantext.Ends (Frontends)
import Gargantext.Sessions (Session)
import Gargantext.Sessions (Session)
import Gargantext.Types (CTabNgramType(..), TabSubType(..), TabType(..))
import Gargantext.Types (CTabNgramType(..), TabSubType(..), TabType(..))
...
...
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