Commit 64775feb authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[ngrams] cache on/off properly

With cache off, we use different loader to allow for page, string, etc
queries directly to the API.
parent 53f08d0c
...@@ -20,7 +20,7 @@ import Data.Sequence as Seq ...@@ -20,7 +20,7 @@ import Data.Sequence as Seq
import Data.Set (Set) import Data.Set (Set)
import Data.Set as Set import Data.Set as Set
import Data.Symbol (SProxy(..)) import Data.Symbol (SProxy(..))
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..), fst)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log) import DOM.Simple.Console (log)
import Effect (Effect) import Effect (Effect)
...@@ -544,12 +544,11 @@ mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt ...@@ -544,12 +544,11 @@ mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt
, tabNgramType , tabNgramType
, tabType , tabType
, withAutoUpdate } _ = do , withAutoUpdate } _ = do
let path = initialPageParams session nodeId [defaultListId] tabType
let render versioned = mainNgramsTablePaint { afterSync, path, tabNgramType, versioned, withAutoUpdate }
case cacheState of case cacheState of
(NT.CacheOn /\ _) -> (NT.CacheOn /\ _) -> do
let path = initialPageParams session nodeId [defaultListId] tabType
let render versioned = mainNgramsTablePaint { afterSync, path, tabNgramType, versioned, withAutoUpdate }
useLoaderWithCacheAPI { useLoaderWithCacheAPI {
cacheEndpoint: versionEndpoint props cacheEndpoint: versionEndpoint props
, handleResponse , handleResponse
...@@ -557,16 +556,39 @@ mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt ...@@ -557,16 +556,39 @@ mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt
, path , path
, renderer: render , renderer: render
} }
(NT.CacheOff /\ _) -> (NT.CacheOff /\ _) -> do
useLoader path loader render path <- R.useState' $ initialPageParams session nodeId [defaultListId] tabType
let render versioned = mainNgramsTablePaintWithState { afterSync, path, tabNgramType, versioned, withAutoUpdate }
useLoader (fst path) loader render
versionEndpoint :: Record MainNgramsTableProps -> PageParams -> Aff Version versionEndpoint :: Record MainNgramsTableProps -> PageParams -> Aff Version
versionEndpoint { defaultListId, nodeId, session, tabType } _ = get session $ R.GetNgramsTableVersion { listId: defaultListId, tabType } (Just nodeId) versionEndpoint { defaultListId, nodeId, session, tabType } _ = get session $ R.GetNgramsTableVersion { listId: defaultListId, tabType } (Just nodeId)
-- NOTE With cache off
loader :: PageParams -> Aff VersionedNgramsTable loader :: PageParams -> Aff VersionedNgramsTable
loader path@{ listIds, nodeId, session, tabType } = loader path@{ listIds
get session $ R.GetNgramsTableAll { listIds, tabType } (Just nodeId) , nodeId
, params: { limit, offset, orderBy }
, searchQuery
, session
, tabType
, termListFilter
, termSizeFilter
} =
get session $ R.GetNgrams params (Just nodeId)
where
params = { limit
, listIds
, offset: Just offset
, orderBy: Nothing -- TODO
, searchQuery
, tabType
, termListFilter
, termSizeFilter
}
-- NOTE With cache on
mkRequest :: PageParams -> GUC.Request mkRequest :: PageParams -> GUC.Request
mkRequest path@{ session } = GUC.makeGetRequest session $ url path mkRequest path@{ session } = GUC.makeGetRequest session $ url path
where where
...@@ -584,10 +606,6 @@ mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt ...@@ -584,10 +606,6 @@ mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt
handleResponse :: VersionedNgramsTable -> VersionedNgramsTable handleResponse :: VersionedNgramsTable -> VersionedNgramsTable
handleResponse v = v handleResponse v = v
pathNoLimit :: PageParams -> PageParams
pathNoLimit path@{ params } = path { params = params { limit = 100000 }
, termListFilter = Nothing }
type MainNgramsTablePaintProps = type MainNgramsTablePaintProps =
( afterSync :: Unit -> Aff Unit ( afterSync :: Unit -> Aff Unit
, path :: PageParams , path :: PageParams
...@@ -615,6 +633,32 @@ mainNgramsTablePaintCpt = R.hooksComponentWithModule thisModule "mainNgramsTable ...@@ -615,6 +633,32 @@ mainNgramsTablePaintCpt = R.hooksComponentWithModule thisModule "mainNgramsTable
, withAutoUpdate , withAutoUpdate
} }
type MainNgramsTablePaintWithStateProps =
( afterSync :: Unit -> Aff Unit
, path :: R.State PageParams
, tabNgramType :: CTabNgramType
, versioned :: VersionedNgramsTable
, withAutoUpdate :: Boolean
)
mainNgramsTablePaintWithState :: Record MainNgramsTablePaintWithStateProps -> R.Element
mainNgramsTablePaintWithState p = R.createElement mainNgramsTablePaintWithStateCpt p []
mainNgramsTablePaintWithStateCpt :: R.Component MainNgramsTablePaintWithStateProps
mainNgramsTablePaintWithStateCpt = R.hooksComponentWithModule thisModule "mainNgramsTablePaintWithState" cpt
where
cpt { afterSync, path, tabNgramType, versioned, withAutoUpdate } _ = do
state <- R.useState' $ initialState versioned
pure $ loadedNgramsTable {
afterSync
, path
, state
, tabNgramType
, versioned
, withAutoUpdate
}
type NgramsOcc = { occurrences :: Additive Int, children :: Set NgramsTerm } type NgramsOcc = { occurrences :: Additive Int, children :: Set NgramsTerm }
ngramsElementToNgramsOcc :: NgramsElement -> NgramsOcc ngramsElementToNgramsOcc :: NgramsElement -> NgramsOcc
......
...@@ -427,7 +427,7 @@ loadCorpus {nodeId, session} = do ...@@ -427,7 +427,7 @@ loadCorpus {nodeId, session} = do
loadCorpusWithChild :: Record LoadProps -> Aff CorpusData loadCorpusWithChild :: Record LoadProps -> Aff CorpusData
loadCorpusWithChild {nodeId:childId, session} = do loadCorpusWithChild { nodeId: childId, session } = do
-- fetch corpus via lists parentId -- fetch corpus via lists parentId
(NodePoly {parentId: corpusId} :: NodePoly {}) <- get session $ listNodeRoute childId "" (NodePoly {parentId: corpusId} :: NodePoly {}) <- get session $ listNodeRoute childId ""
corpusNode <- get session $ corpusNodeRoute corpusId "" corpusNode <- get session $ corpusNodeRoute corpusId ""
...@@ -435,7 +435,7 @@ loadCorpusWithChild {nodeId:childId, session} = do ...@@ -435,7 +435,7 @@ loadCorpusWithChild {nodeId:childId, session} = do
:: forall a. DecodeJson a => AffTableResult (NodePoly a) :: forall a. DecodeJson a => AffTableResult (NodePoly a)
case (A.head defaultListIds.docs :: Maybe (NodePoly HyperdataList)) of case (A.head defaultListIds.docs :: Maybe (NodePoly HyperdataList)) of
Just (NodePoly { id: defaultListId }) -> Just (NodePoly { id: defaultListId }) ->
pure {corpusId, corpusNode, defaultListId} pure { corpusId, corpusNode, defaultListId }
Nothing -> Nothing ->
throwError $ error "Missing default list" throwError $ error "Missing default list"
where where
......
...@@ -15,6 +15,7 @@ import Gargantext.Prelude ...@@ -15,6 +15,7 @@ import Gargantext.Prelude
import Gargantext.Sessions (Session, sessionId) import Gargantext.Sessions (Session, sessionId)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
thisModule :: String
thisModule = "Gargantext.Components.Nodes.Lists" thisModule = "Gargantext.Components.Nodes.Lists"
------------------------------------------------------------------------ ------------------------------------------------------------------------
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -53,9 +54,9 @@ listsLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "listsLayoutWithKe ...@@ -53,9 +54,9 @@ listsLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "listsLayoutWithKe
useLoader path loadCorpusWithChild $ useLoader path loadCorpusWithChild $
\corpusData@{ corpusId, corpusNode: NodePoly poly, defaultListId } -> \corpusData@{ corpusId, corpusNode: NodePoly poly, defaultListId } ->
let { date, hyperdata : Hyperdata h, name } = poly let { date, hyperdata : Hyperdata h, name } = poly
CorpusInfo {desc,query,authors} = getCorpusInfo h.fields CorpusInfo { authors, desc, query } = getCorpusInfo h.fields
in in
R.fragment [ R.fragment [
Table.tableHeaderLayout { Table.tableHeaderLayout {
afterCacheStateChange: \_ -> launchAff_ $ clearCache unit afterCacheStateChange: \_ -> launchAff_ $ clearCache unit
......
...@@ -18,6 +18,7 @@ import Gargantext.Components.Search ...@@ -18,6 +18,7 @@ import Gargantext.Components.Search
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix (effectLink) import Gargantext.Utils.Reactix (effectLink)
thisModule :: String
thisModule = "Gargantext.Components.Table" thisModule = "Gargantext.Components.Table"
type TableContainerProps = type TableContainerProps =
...@@ -33,9 +34,9 @@ type Rows = Seq.Seq Row ...@@ -33,9 +34,9 @@ type Rows = Seq.Seq Row
type OrderBy = Maybe (OrderByDirection ColumnName) type OrderBy = Maybe (OrderByDirection ColumnName)
type Params = { offset :: Int type Params = { limit :: Int
, limit :: Int , offset :: Int
, orderBy :: OrderBy , orderBy :: OrderBy
, searchType :: SearchType , searchType :: SearchType
} }
...@@ -62,18 +63,18 @@ derive instance eqOrderByDirection :: Eq a => Eq (OrderByDirection a) ...@@ -62,18 +63,18 @@ derive instance eqOrderByDirection :: Eq a => Eq (OrderByDirection a)
type Props = type Props =
( colNames :: Array ColumnName ( colNames :: Array ColumnName
, wrapColElts :: ColumnName -> Array R.Element -> Array R.Element , container :: Record TableContainerProps -> R.Element
-- ^ Use `const identity` as a default behavior.
, totalRecords :: Int
, params :: R.State Params , params :: R.State Params
, rows :: Rows , rows :: Rows
, container :: Record TableContainerProps -> R.Element , totalRecords :: Int
, wrapColElts :: ColumnName -> Array R.Element -> Array R.Element
-- ^ Use `const identity` as a default behavior.
) )
type State = type State =
{ page :: Int { page :: Int
, pageSize :: PageSizes , pageSize :: PageSizes
, orderBy :: OrderBy , orderBy :: OrderBy
, searchType :: SearchType , searchType :: SearchType
} }
......
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