Commit d9830525 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[ngrams] fix cache API

Turns out caches.delete() didn't return a promise.

Also small improvements to Ngrams get (use ngrams get all endpoint).
parent 9c69108b
......@@ -22,8 +22,13 @@ import Data.Set as Set
import Data.Symbol (SProxy(..))
import Data.Tuple (Tuple(..), fst, snd)
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import Effect (Effect)
import Effect.Aff (Aff)
import Reactix as R
import Reactix.DOM.HTML as H
import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Components.AutoUpdate (autoUpdateElt)
import Gargantext.Components.NgramsTable.Components as NTC
import Gargantext.Components.NgramsTable.Core
......@@ -37,9 +42,6 @@ import Gargantext.Utils (queryMatchesLabel, toggleSet)
import Gargantext.Utils.CacheAPI as GUC
import Gargantext.Utils.List (sortWith) as L
import Gargantext.Utils.Reactix as R2
import Reactix (Component, Element, State, createElement, fragment, hooksComponent, useState') as R
import Reactix.DOM.HTML as H
import Unsafe.Coerce (unsafeCoerce)
type State' =
CoreState
......@@ -492,7 +494,7 @@ mainNgramsTable props = R.createElement mainNgramsTableCpt props []
mainNgramsTableCpt :: R.Component MainNgramsTableProps
mainNgramsTableCpt = R.hooksComponent "G.C.NT.mainNgramsTable" cpt
where
cpt props@{nodeId, defaultListId, tabType, session, tabNgramType, withAutoUpdate} _ = do
cpt props@{nodeId, defaultListId, session, tabNgramType, tabType, withAutoUpdate} _ = do
let path = initialPageParams session nodeId [defaultListId] tabType
useLoaderWithCacheAPI {
......@@ -517,14 +519,16 @@ mainNgramsTableCpt = R.hooksComponent "G.C.NT.mainNgramsTable" cpt
, tabType
, termListFilter
, termSizeFilter
} = R.GetNgrams { limit
, listIds
, offset: Just offset
, orderBy: convOrderBy <$> orderBy
, searchQuery
, tabType
, termListFilter
, termSizeFilter } (Just nodeId)
} = R.GetNgramsTableAll { listIds
, tabType } (Just nodeId)
-- } = R.GetNgrams { limit
-- , listIds
-- , offset: Just offset
-- , orderBy: convOrderBy <$> orderBy
-- , searchQuery
-- , tabType
-- , termListFilter
-- , termSizeFilter } (Just nodeId)
handleResponse :: VersionedNgramsTable -> VersionedNgramsTable
handleResponse v = v
......@@ -548,8 +552,13 @@ mainNgramsTablePaintCpt :: R.Component MainNgramsTablePaintProps
mainNgramsTablePaintCpt = R.hooksComponent "G.C.NT.mainNgramsTablePaint" cpt
where
cpt {path, tabNgramType, versioned, withAutoUpdate} _ = do
R.useEffect' $ do
let (Versioned v) = versioned
log2 "[mainNgramsTablePaint] versioned values" $ show v.data
pathS <- R.useState' path
state <- R.useState' $ initialState versioned
pure $ loadedNgramsTable {
path: pathS
, state
......
......@@ -203,6 +203,9 @@ _list :: forall a row. Lens' { list :: a | row } a
_list = prop (SProxy :: SProxy "list")
derive instance newtypeNgramsElement :: Newtype NgramsElement _
derive instance genericNgramsElement :: Generic NgramsElement _
instance showNgramsElement :: Show NgramsElement where
show = genericShow
_NgramsElement :: Iso' NgramsElement {
children :: Set NgramsTerm
......@@ -262,7 +265,11 @@ instance decodeJsonVersioned :: DecodeJson a => DecodeJson (Versioned a) where
newtype NgramsTable = NgramsTable (Map NgramsTerm NgramsElement)
derive instance newtypeNgramsTable :: Newtype NgramsTable _
derive instance eqNgramsTable :: Eq NgramsTable
derive instance genericNgramsTable :: Generic NgramsTable _
instance eqNgramsTable :: Eq NgramsTable where
eq = genericEq
instance showNgramsTable :: Show NgramsTable where
show = genericShow
_NgramsTable :: Iso' NgramsTable (Map NgramsTerm NgramsElement)
_NgramsTable = _Newtype
......@@ -738,14 +745,17 @@ loadNgramsTable
{ nodeId, listIds, termListFilter, termSizeFilter, session, scoreType
, searchQuery, tabType, params: {offset, limit, orderBy}}
= get session query
where query = GetNgrams { limit
, offset: Just offset
, listIds
, orderBy: convOrderBy <$> orderBy
, searchQuery
, tabType
, termListFilter
, termSizeFilter } (Just nodeId)
where
query = GetNgramsTableAll { listIds
, tabType } (Just nodeId)
-- where query = GetNgrams { limit
-- , offset: Just offset
-- , listIds
-- , orderBy: convOrderBy <$> orderBy
-- , searchQuery
-- , tabType
-- , termListFilter
-- , termSizeFilter } (Just nodeId)
type NgramsListByTabType = Map TabType VersionedNgramsTable
......@@ -758,7 +768,7 @@ loadNgramsTableAll { nodeId, listIds, session, scoreType } = do
, CTabAuthors
, CTabInstitutes
]
query tabType = GetNgramsTableAll { tabType, listIds, scoreType } (Just nodeId)
query tabType = GetNgramsTableAll { listIds, tabType } (Just nodeId)
Map.fromFoldable <$> for cTagNgramTypes \cTagNgramType -> do
let tabType = TabCorpus $ TabNgramType cTagNgramType
......
......@@ -4,6 +4,7 @@ import Data.Argonaut (class DecodeJson)
import Data.Maybe (Maybe(..), maybe, isJust)
import Data.Tuple (fst)
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log, log2)
import Effect.Aff (Aff, launchAff_, throwError)
import Effect.Class (liftEffect)
import Effect.Exception (error)
......@@ -72,6 +73,10 @@ useCachedAPILoaderEffect { cacheEndpoint
val <- if version == cacheReal then
pure vr
else do
-- liftEffect $ do
-- log "[useCachedAPILoaderEffect] versions dont match"
-- log2 "[useCachedAPILoaderEffect] cached version" version
-- log2 "[useCachedAPILoaderEffect] real version" cacheReal
_ <- GUC.delete cache req
vr@(Versioned { version, "data": d }) <- GUC.cachedJson cache req
if version == cacheReal then
......
......@@ -29,15 +29,15 @@ tabs props = R.createElement tabsCpt props []
tabsCpt :: R.Component Props
tabsCpt = R.hooksComponent "G.C.N.L.T.tabs" cpt
where
cpt {session, corpusId, corpusData: corpusData@{defaultListId}} _ = do
cpt { corpusData: corpusData@{ defaultListId }, corpusId, session } _ = do
(selected /\ setSelected) <- R.useState' 0
pure $ Tab.tabs { tabs: tabs', selected }
pure $ Tab.tabs { selected, tabs: tabs' }
where
tabs' = [ "Sources" /\ view Sources
, "Authors" /\ view Authors
tabs' = [ "Authors" /\ view Authors
, "Institutes" /\ view Institutes
, "Sources" /\ view Sources
, "Terms" /\ view Terms ]
view mode = ngramsView {mode, session, corpusId, corpusData}
view mode = ngramsView { corpusData, corpusId, mode, session }
type NgramsViewProps = ( mode :: Mode | Props )
......@@ -47,7 +47,7 @@ ngramsView props = R.createElement ngramsViewCpt props []
ngramsViewCpt :: R.Component NgramsViewProps
ngramsViewCpt = R.hooksComponent "G.C.N.L.T.ngramsView" cpt
where
cpt { corpusData: {defaultListId}
cpt { corpusData: { defaultListId }
, corpusId
, mode
, session } _ = do
......@@ -55,11 +55,11 @@ ngramsViewCpt = R.hooksComponent "G.C.N.L.T.ngramsView" cpt
pure $ R.fragment
( charts tabNgramType chartType
<> [ NT.mainNgramsTable { session
, defaultListId
<> [ NT.mainNgramsTable { defaultListId
, nodeId: corpusId
, tabType
, session
, tabNgramType
, tabType
, withAutoUpdate: false
}
]
......@@ -69,9 +69,9 @@ ngramsViewCpt = R.hooksComponent "G.C.N.L.T.ngramsView" cpt
tabType = TabCorpus (TabNgramType tabNgramType)
listId = defaultListId
path = { corpusId
, limit: Just 1000
, listId
, tabType
, limit: Just 1000
}
charts CTabTerms (chartType /\ setChartType) = [
......
......@@ -128,8 +128,7 @@ sessionPath (R.RecomputeListChart _ nt nId lId) = "node/" <> (show nId)
sessionPath (R.GraphAPI gId p) = "graph/" <> (show gId) <> "/" <> p
sessionPath (R.GetNgrams opts i) =
base opts.tabType
$ "ngrams?ngramsType="
<> showTabType' opts.tabType
$ "ngrams?ngramsType=" <> showTabType' opts.tabType
<> limitUrl opts.limit
<> offset opts.offset
<> orderByUrl opts.orderBy
......@@ -157,6 +156,8 @@ sessionPath (R.GetNgramsTableVersion opts i) =
$ "ngrams/version?ngramsType="
<> showTabType' opts.tabType
<> "&list=" <> show opts.listId
-- $ "ngrams/version?"
-- <> "list=" <> show opts.listId
sessionPath (R.ListDocument lId dId) =
sessionPath $ R.NodeAPI NodeList lId ("document/" <> (show $ fromMaybe 0 dId))
sessionPath (R.ListsRoute lId) = "lists/" <> show lId
......
......@@ -342,20 +342,19 @@ instance showScoreType :: Show ScoreType where
type SearchQuery = String
type NgramsGetOpts =
{ tabType :: TabType
, limit :: Limit
{ limit :: Limit
, listIds :: Array ListId
, offset :: Maybe Offset
, orderBy :: Maybe OrderBy
, listIds :: Array ListId
, searchQuery :: SearchQuery
, tabType :: TabType
, termListFilter :: Maybe TermList
, termSizeFilter :: Maybe TermSize
, searchQuery :: SearchQuery
}
type NgramsGetTableAllOpts =
{ tabType :: TabType
, listIds :: Array ListId
, scoreType :: ScoreType
{ listIds :: Array ListId
, tabType :: TabType
}
type SearchOpts =
......@@ -566,14 +565,14 @@ instance encodeMode :: EncodeJson Mode where
modeTabType :: Mode -> CTabNgramType
modeTabType Authors = CTabAuthors
modeTabType Sources = CTabSources
modeTabType Institutes = CTabInstitutes
modeTabType Sources = CTabSources
modeTabType Terms = CTabTerms
modeFromString :: String -> Maybe Mode
modeFromString "Authors" = Just Authors
modeFromString "Sources" = Just Sources
modeFromString "Institutes" = Just Institutes
modeFromString "Sources" = Just Sources
modeFromString "Terms" = Just Terms
modeFromString _ = Nothing
......
......@@ -16,7 +16,7 @@ exports._openCache = function(cacheName) {
exports._delete = function(cache) {
return function(req) {
return function() {
cache.delete(req);
return cache.delete(req);
}
}
}
......
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