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

[ngrams] migrate T.Rows to List

This could be more performant than Array. We don't do random access,
only filtering.
parent 71c324f8
......@@ -10,6 +10,7 @@ import Data.Generic.Rep.Show (genericShow)
import Data.Lens ((^.))
import Data.Lens.At (at)
import Data.Lens.Record (prop)
import Data.List as L
import Data.Map (Map)
import Data.Map as Map
import Data.Maybe (Maybe(..), maybe)
......@@ -393,7 +394,7 @@ pageCpt = R.memo' $ R.hooksComponent "G.C.DocsTable.pageCpt" cpt where
{ colNames
, container: T.defaultContainer { title: "Documents" }
, params
, rows: rows localCategories
, rows: L.fromFoldable $ rows localCategories
, totalRecords
, wrapColElts
}
......
......@@ -8,6 +8,7 @@ import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyO
import Data.Array (concat, filter)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.List as L
import Data.Maybe (Maybe(..))
import Data.Set (Set)
import Data.Set as Set
......@@ -332,7 +333,7 @@ pageCpt = R.hooksComponent "G.C.FacetsTable.Page" cpt
documentUrl id =
url frontends $ Routes.CorpusDocument (sessionId session) nodeId listId id
comma = H.span {} [ H.text ", " ]
rows = row <$> filter (not <<< isDeleted) documents
rows = L.fromFoldable $ row <$> filter (not <<< isDeleted) documents
row dv@(DocumentsView {id, score, title, source, authors, pairs, delete, category}) =
{ row:
T.makeRow [
......
......@@ -11,7 +11,7 @@ import Data.Lens.Common (_Just)
import Data.Lens.Fold (folded)
import Data.Lens.Index (ix)
import Data.Lens.Record (prop)
import Data.List as List
import Data.List as L
import Data.Map (Map)
import Data.Map as Map
import Data.Maybe (Maybe(..), maybe, isJust)
......@@ -39,6 +39,7 @@ import Gargantext.Components.Table as T
import Gargantext.Sessions (Session)
import Gargantext.Types (CTabNgramType, OrderBy(..), SearchQuery, TabType, TermList(..), readTermList, readTermSize, termLists, termSizes)
import Gargantext.Utils (queryMatchesLabel, toggleSet)
import Gargantext.Utils.List as L
import Gargantext.Utils.Reactix as R2
type State' =
......@@ -402,13 +403,13 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt
setState $ setParentResetChildren Nothing
commitPatchR (Versioned {version: ngramsVersion, data: pt}) (state /\ setState)
totalRecords = A.length rows
totalRecords = L.length rows
filteredRows = T.filterRows { params } rows
rows :: T.Rows
rows = convertRow
<$> orderWith (
addOcc
<$> List.fromFoldable (Map.toUnfoldable (Map.filter rowsFilter (ngramsTable ^. _NgramsTable)))
<$> Map.toUnfoldable (Map.filter rowsFilter (ngramsTable ^. _NgramsTable))
)
rowsFilter = displayRow state searchQuery versioned termListFilter
addOcc (Tuple ne ngramsElement) =
......@@ -429,10 +430,10 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt
}
orderWith =
case convOrderBy <$> params.orderBy of
Just ScoreAsc -> List.sortBy \x -> (snd x) ^. _NgramsElement <<< _occurrences
Just ScoreDesc -> List.sortBy \x -> Down $ (snd x) ^. _NgramsElement <<< _occurrences
Just TermAsc -> List.sortBy \x -> (snd x) ^. _NgramsElement <<< _ngrams
Just TermDesc -> List.sortBy \x -> Down $ (snd x) ^. _NgramsElement <<< _ngrams
Just ScoreAsc -> L.sortWith \x -> (snd x) ^. _NgramsElement <<< _occurrences
Just ScoreDesc -> L.sortWith \x -> Down $ (snd x) ^. _NgramsElement <<< _occurrences
Just TermAsc -> L.sortWith \x -> (snd x) ^. _NgramsElement <<< _ngrams
Just TermDesc -> L.sortWith \x -> Down $ (snd x) ^. _NgramsElement <<< _ngrams
_ -> identity -- the server ordering is enough here
colNames = T.ColumnName <$> ["Select", "Map", "Stop", "Terms", "Score"] -- see convOrderBy
......@@ -569,7 +570,7 @@ treeCpt = R.hooksComponent "G.C.NT.tree" cpt
, H.i { className: "glyphicon glyphicon-pencil"
, on: { click: const effect } } []
]
leaf = List.null cs
leaf = L.null cs
className = "glyphicon glyphicon-chevron-" <> if open then "down" else "right"
style = if leaf then {color: "#adb5bd"} else {color: ""}
open = not leaf || false {- TODO -}
......@@ -577,7 +578,7 @@ treeCpt = R.hooksComponent "G.C.NT.tree" cpt
forest =
let depth = ngramsDepth.depth + 1 in
H.ul {} <<< map (\ngrams -> tree (params { ngramsDepth = {depth, ngrams} })) <<< List.toUnfoldable
H.ul {} <<< map (\ngrams -> tree (params { ngramsDepth = {depth, ngrams} })) <<< L.toUnfoldable
sumOccurrences' :: NgramsTable -> NgramsTerm -> Additive Int
sumOccurrences' ngramsTable label =
......
......@@ -2,13 +2,15 @@ module Gargantext.Components.Nodes.Annuaire where
import Prelude (bind, const, identity, pure, ($), (<$>), (<>))
import Data.Argonaut (class DecodeJson, decodeJson, (.:), (.:?))
import Data.Array (head)
import Data.Array as A
import Data.List as L
import Data.Maybe (Maybe(..), maybe)
import Data.Tuple (fst, snd)
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff)
import Reactix as R
import Reactix.DOM.HTML as H
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types as CT
import Gargantext.Components.Table as T
import Gargantext.Ends (url, Frontends)
......@@ -119,7 +121,7 @@ pageCpt = R.hooksComponent "LoadedAnnuairePage" cpt
, frontends
, contact: c
, session }
, delete: false }) <$> docs
, delete: false }) <$> L.fromFoldable docs
container = T.defaultContainer { title: "Annuaire" } -- TODO
colNames = T.ColumnName <$> [ "", "Name", "Company", "Service", "Role"]
wrapColElts = const identity
......@@ -165,10 +167,10 @@ contactCellsCpt = R.hooksComponent "G.C.N.A.contactCells" cpt
H.text ""
, H.a { href } [ H.text $ maybe "name" identity contact.title ]
--, H.a { href, target: "blank" } [ H.text $ maybe "name" identity contact.title ]
, H.text $ maybe "No ContactWhere" contactWhereOrg (head $ ou)
, H.text $ maybe "No ContactWhereDept" contactWhereDept (head $ ou)
, H.text $ maybe "No ContactWhere" contactWhereOrg (A.head $ ou)
, H.text $ maybe "No ContactWhereDept" contactWhereDept (A.head $ ou)
, H.div {className: "nooverflow"} [
H.text $ maybe "No ContactWhereRole" contactWhereRole (head $ ou)
H.text $ maybe "No ContactWhereRole" contactWhereRole (A.head $ ou)
]
]
where
......@@ -178,10 +180,10 @@ contactCellsCpt = R.hooksComponent "G.C.N.A.contactCells" cpt
contactWhereOrg (CT.ContactWhere { organization: [] }) = "No Organization"
contactWhereOrg (CT.ContactWhere { organization: orga }) =
maybe "No orga (list)" identity (head orga)
maybe "No orga (list)" identity (A.head orga)
contactWhereDept (CT.ContactWhere { labTeamDepts : [] }) = "Empty Dept"
contactWhereDept (CT.ContactWhere { labTeamDepts : dept }) =
maybe "No Dept (list)" identity (head dept)
maybe "No Dept (list)" identity (A.head dept)
contactWhereRole (CT.ContactWhere { role: Nothing }) = "Empty Role"
contactWhereRole (CT.ContactWhere { role: Just role }) = role
......
......@@ -4,6 +4,7 @@ import Prelude
import Data.Array as A
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.List as L
import Data.Maybe (Maybe(..))
import Data.Tuple (fst, snd)
import Data.Tuple.Nested ((/\))
......@@ -22,7 +23,7 @@ type TableContainerProps =
)
type Row = { row :: R.Element, delete :: Boolean }
type Rows = Array Row
type Rows = L.List Row
type OrderBy = Maybe (OrderByDirection ColumnName)
......@@ -154,7 +155,7 @@ tableCpt = R.hooksComponent "G.C.Table.table" cpt
{ pageSizeControl: sizeDD { params }
, pageSizeDescription: textDescription state.page state.pageSize totalRecords
, paginationLinks: pagination params totalPages
, tableBody: map _.row rows
, tableBody: map _.row $ A.fromFoldable rows
, tableHead: H.tr {} (colHeader <$> colNames)
}
......@@ -170,7 +171,7 @@ type FilterRowsParams =
filterRows :: Record FilterRowsParams -> Rows -> Rows
filterRows { params: { limit, offset, orderBy } } rs = newRs
where
newRs = A.take limit $ A.drop offset $ rs
newRs = L.take limit $ L.drop offset $ rs
defaultContainer :: {title :: String} -> Record TableContainerProps -> R.Element
defaultContainer {title} props = R.fragment
......
......@@ -11,7 +11,8 @@ defaultBackends = local :| [prod, partner, demo, dev]
partner = backend V10 "/api/" "https://imtv4.gargantext.org" "institut-mines-telecom.imt"
demo = backend V10 "/api/" "https://demo.gargantext.org" "demo.inshs.cnrs"
dev = backend V10 "/api/" "https://dev.gargantext.org" "devel.inshs.cnrs"
local = backend V10 "/api/" "http://localhost:8008" "local.cnrs"
-- local = backend V10 "/api/" "http://localhost:8008" "local.cnrs"
local = backend V10 "/api/" "http://192.168.1.8:8008" "local.cnrs"
defaultApps :: NonEmpty Array Frontend
defaultApps = relative :| [prod, dev, demo, haskell, caddy]
......@@ -20,7 +21,8 @@ defaultApps = relative :| [prod, dev, demo, haskell, caddy]
prod = frontend "/#/" "https://v4.gargantext.org" "v4.gargantext.org"
dev = frontend "/#/" "https://dev.gargantext.org" "gargantext.org (dev)"
demo = frontend "/#/" "https://demo.gargantext.org" "gargantext.org (demo)"
haskell = frontend "/#/" "http://localhost:8008" "localhost.gargantext"
-- haskell = frontend "/#/" "http://localhost:8008" "localhost.gargantext"
haskell = frontend "/#/" "http://192.168.1.8:8008" "localhost.gargantext"
python = frontend "/#/" "http://localhost:8000" "localhost.python"
caddy = frontend "/#/" "http://localhost:2015" "localhost.caddy"
......
module Gargantext.Utils.List where
import Data.Ord (class Ord, comparing)
import Data.List as List
-- same as
-- https://github.com/purescript/purescript-arrays/blob/v5.3.1/src/Data/Array.purs#L715-L715
sortWith :: forall a b. Ord b => (a -> b) -> List.List a -> List.List a
sortWith f = List.sortBy (comparing f)
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