Commit cf8f8cb2 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski Committed by Alexandre Delanoë

[ngrams] performance fix for ngrams table that I broke

I broke it in previous commit, by not caching ngramsTable in displayRow
and instead recomputing it every time from initTable.
parent 8f1f26d4
...@@ -402,9 +402,6 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt ...@@ -402,9 +402,6 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt
, ngramsSelectAll = false } , ngramsSelectAll = false }
toggler s = s { ngramsSelection = roots toggler s = s { ngramsSelection = roots
, ngramsSelectAll = true } , ngramsSelectAll = true }
where
ngramsTable = applyNgramsPatches state initTable
roots = rootsOf ngramsTable
performAction Synchronize = syncPatchesR path' (state /\ setState) performAction Synchronize = syncPatchesR path' (state /\ setState)
performAction (CommitPatch pt) = performAction (CommitPatch pt) =
commitPatchR (Versioned {version: ngramsVersion, data: pt}) (state /\ setState) commitPatchR (Versioned {version: ngramsVersion, data: pt}) (state /\ setState)
...@@ -431,12 +428,13 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt ...@@ -431,12 +428,13 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt
<$> Map.toUnfoldable (Map.filter rowsFilter (ngramsTable ^. _NgramsTable)) <$> Map.toUnfoldable (Map.filter rowsFilter (ngramsTable ^. _NgramsTable))
) )
rowsFilter :: NgramsElement -> Boolean rowsFilter :: NgramsElement -> Boolean
rowsFilter = displayRow state searchQuery versioned termListFilter rowsFilter = displayRow state searchQuery ngramsTable termListFilter
addOcc (Tuple ne ngramsElement) = addOcc (Tuple ne ngramsElement) =
let Additive occurrences = sumOccurrences ngramsTable ngramsElement in let Additive occurrences = sumOccurrences ngramsTable ngramsElement in
Tuple ne (ngramsElement # _NgramsElement <<< _occurrences .~ occurrences) Tuple ne (ngramsElement # _NgramsElement <<< _occurrences .~ occurrences)
ngramsTable = applyNgramsPatches state initTable ngramsTable = applyNgramsPatches state initTable
roots = rootsOf ngramsTable
convertRow (Tuple ngrams ngramsElement) = convertRow (Tuple ngrams ngramsElement) =
{ row: renderNgramsItem { dispatch: performAction { row: renderNgramsItem { dispatch: performAction
...@@ -476,12 +474,12 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt ...@@ -476,12 +474,12 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt
setSearchQuery x = setPath $ _ { searchQuery = x } setSearchQuery x = setPath $ _ { searchQuery = x }
displayRow :: State -> SearchQuery -> VersionedNgramsTable -> Maybe TermList -> NgramsElement -> Boolean displayRow :: State -> SearchQuery -> NgramsTable -> Maybe TermList -> NgramsElement -> Boolean
displayRow state@{ ngramsChildren displayRow state@{ ngramsChildren
, ngramsLocalPatch , ngramsLocalPatch
, ngramsParent } , ngramsParent }
searchQuery searchQuery
(Versioned { data: initTable }) ngramsTable
termListFilter termListFilter
(NgramsElement {ngrams, root, list}) = (NgramsElement {ngrams, root, list}) =
root == Nothing root == Nothing
...@@ -501,7 +499,6 @@ displayRow state@{ ngramsChildren ...@@ -501,7 +499,6 @@ displayRow state@{ ngramsChildren
|| tablePatchHasNgrams ngramsLocalPatch ngrams || tablePatchHasNgrams ngramsLocalPatch ngrams
-- ^ unless they are being processed at the moment. -- ^ unless they are being processed at the moment.
where where
ngramsTable = applyNgramsPatches state initTable
ngramsParentRoot :: Maybe NgramsTerm ngramsParentRoot :: Maybe NgramsTerm
ngramsParentRoot = ngramsParentRoot =
(\np -> ngramsTable ^? at np (\np -> ngramsTable ^? at np
......
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