link: minimal initial view result

On initial load, instead of getting the first 25 links for every
collection, only get their totals and unread counts. This drastically
reduces the pageload time.

Updates the frontend to match:
- Handle initial results without link content.
- Dynamically load in collection's links, even for page 0.
This commit is contained in:
Fang 2020-04-13 21:26:09 +02:00
parent bf42afbd56
commit 8f3d174c94
No known key found for this signature in database
GPG Key ID: EB035760C1BBA972
3 changed files with 37 additions and 17 deletions

View File

@ -1,13 +1,13 @@
:: link-view: frontend endpoints :: link-view: frontend endpoints
:: ::
:: endpoints, mapping onto link-store's paths. p is for page as in pagination. :: endpoints, mapping onto link-store's paths. p is for page as in pagination.
:: updates only work for page 0. :: only the /0/submissions endpoint provides updates.
:: as with link-store, urls are expected to use +wood encoding. :: as with link-store, urls are expected to use +wood encoding.
:: ::
:: /json/[p]/submissions pages for all groups :: /json/0/submissions initial + updates for all
:: /json/[p]/submissions/[some-group] page for one group :: /json/[p]/submissions/[collection] page for one collection
:: /json/[p]/discussions/[wood-url]/[some-group] page for url in group :: /json/[p]/discussions/[wood-url]/[collection] page for url in collection
:: /json/[n]/submission/[wood-url]/[some-group] nth matching submission :: /json/[n]/submission/[wood-url]/[collection] nth matching submission
:: /json/seen mark-as-read updates :: /json/seen mark-as-read updates
:: ::
/- *link-view, /- *link-view,
@ -491,9 +491,11 @@
:: ::
++ give-initial-submissions ++ give-initial-submissions
~/ %link-view-initial-submissions ~/ %link-view-initial-submissions
|= [p=@ud =path] |= [p=@ud =requested=path]
^- (list card) ^- (list card)
:_ ?: =(0 p) ~ :_ :: only keep the base case alive (for updates), kick all others
::
?: &(=(0 p) ?=(~ requested-path)) ~
[%give %kick ~ ~]~ [%give %kick ~ ~]~
=; =json =; =json
[%give %fact ~ %json !>(json)] [%give %fact ~ %json !>(json)]
@ -501,9 +503,9 @@
%- pairs:enjs:format %- pairs:enjs:format
%+ turn %+ turn
%~ tap by %~ tap by
%+ scry-for (map ^path submissions) %+ scry-for (map path submissions)
[%submissions path] [%submissions requested-path]
|= [=^path =submissions] |= [=path =submissions]
^- [@t json] ^- [@t json]
:- (spat path) :- (spat path)
=; =json =; =json
@ -516,6 +518,15 @@
%~ wyt in %~ wyt in
%+ scry-for (set url) %+ scry-for (set url)
[%unseen path] [%unseen path]
?: &(=(0 p) ?=(~ requested-path))
:: for a broad-scope initial result, only give total counts
::
=, enjs:format
%- pairs
=+ l=(lent submissions)
:~ 'totalItems'^(numb l)
'totalPages'^(numb (div l page-size))
==
%^ page-to-json p %^ page-to-json p
%+ get-paginated `p %+ get-paginated `p
submissions submissions

View File

@ -19,11 +19,18 @@ export class Links extends Component {
this.componentDidUpdate(); this.componentDidUpdate();
} }
componentDidUpdate() { componentDidUpdate(prevProps) {
const linkPage = this.props.page; const linkPage = this.props.page;
if ( (this.props.page != 0) && // if we just navigated to this particular page,
(!this.props.links[linkPage] || // and don't have links for it yet,
this.props.links.local[linkPage]) // or the links we have might not be complete,
// request the links for that page.
if ( (!prevProps ||
linkPage !== prevProps.page ||
this.props.resourcePath !== prevProps.resourcePath
) &&
!this.props.links[linkPage] ||
this.props.links.local[linkPage]
) { ) {
api.getPage(this.props.resourcePath, this.props.page); api.getPage(this.props.resourcePath, this.props.page);
} }

View File

@ -37,8 +37,10 @@ export class LinkUpdateReducer {
// since data contains an up-to-date full version of the page, // since data contains an up-to-date full version of the page,
// we can safely overwrite the one in state. // we can safely overwrite the one in state.
state.links[path][page] = here.page; if (typeof page === 'number' && here.page) {
state.links[path].local[page] = false; state.links[path][page] = here.page;
state.links[path].local[page] = false;
}
state.links[path].totalPages = here.totalPages; state.links[path].totalPages = here.totalPages;
state.links[path].totalItems = here.totalItems; state.links[path].totalItems = here.totalItems;
state.links[path].unseenCount = here.unseenCount; state.links[path].unseenCount = here.unseenCount;
@ -48,7 +50,7 @@ export class LinkUpdateReducer {
if (!state.seen[path]) { if (!state.seen[path]) {
state.seen[path] = {}; state.seen[path] = {};
} }
here.page.map(submission => { (here.page || []).map(submission => {
state.seen[path][submission.url] = submission.seen; state.seen[path][submission.url] = submission.seen;
}); });
} }