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