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