mirror of
https://github.com/urbit/shrub.git
synced 2024-12-01 06:35:32 +03:00
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:
parent
bf42afbd56
commit
8f3d174c94
@ -1,13 +1,13 @@
|
||||
:: link-view: frontend endpoints
|
||||
::
|
||||
:: 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.
|
||||
::
|
||||
:: /json/[p]/submissions pages for all groups
|
||||
:: /json/[p]/submissions/[some-group] page for one group
|
||||
:: /json/[p]/discussions/[wood-url]/[some-group] page for url in group
|
||||
:: /json/[n]/submission/[wood-url]/[some-group] nth matching submission
|
||||
:: /json/0/submissions initial + updates for all
|
||||
:: /json/[p]/submissions/[collection] page for one collection
|
||||
:: /json/[p]/discussions/[wood-url]/[collection] page for url in collection
|
||||
:: /json/[n]/submission/[wood-url]/[collection] nth matching submission
|
||||
:: /json/seen mark-as-read updates
|
||||
::
|
||||
/- *link-view,
|
||||
@ -491,9 +491,11 @@
|
||||
::
|
||||
++ give-initial-submissions
|
||||
~/ %link-view-initial-submissions
|
||||
|= [p=@ud =path]
|
||||
|= [p=@ud =requested=path]
|
||||
^- (list card)
|
||||
:_ ?: =(0 p) ~
|
||||
:_ :: only keep the base case alive (for updates), kick all others
|
||||
::
|
||||
?: &(=(0 p) ?=(~ requested-path)) ~
|
||||
[%give %kick ~ ~]~
|
||||
=; =json
|
||||
[%give %fact ~ %json !>(json)]
|
||||
@ -501,9 +503,9 @@
|
||||
%- pairs:enjs:format
|
||||
%+ turn
|
||||
%~ tap by
|
||||
%+ scry-for (map ^path submissions)
|
||||
[%submissions path]
|
||||
|= [=^path =submissions]
|
||||
%+ scry-for (map path submissions)
|
||||
[%submissions requested-path]
|
||||
|= [=path =submissions]
|
||||
^- [@t json]
|
||||
:- (spat path)
|
||||
=; =json
|
||||
@ -516,6 +518,15 @@
|
||||
%~ wyt in
|
||||
%+ scry-for (set url)
|
||||
[%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
|
||||
%+ get-paginated `p
|
||||
submissions
|
||||
|
@ -19,11 +19,18 @@ export class Links extends Component {
|
||||
this.componentDidUpdate();
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
componentDidUpdate(prevProps) {
|
||||
const linkPage = this.props.page;
|
||||
if ( (this.props.page != 0) &&
|
||||
(!this.props.links[linkPage] ||
|
||||
this.props.links.local[linkPage])
|
||||
// if we just navigated to this particular page,
|
||||
// and don't have links for it yet,
|
||||
// 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);
|
||||
}
|
||||
|
@ -37,8 +37,10 @@ export class LinkUpdateReducer {
|
||||
|
||||
// since data contains an up-to-date full version of the page,
|
||||
// we can safely overwrite the one in state.
|
||||
state.links[path][page] = here.page;
|
||||
state.links[path].local[page] = false;
|
||||
if (typeof page === 'number' && here.page) {
|
||||
state.links[path][page] = here.page;
|
||||
state.links[path].local[page] = false;
|
||||
}
|
||||
state.links[path].totalPages = here.totalPages;
|
||||
state.links[path].totalItems = here.totalItems;
|
||||
state.links[path].unseenCount = here.unseenCount;
|
||||
@ -48,7 +50,7 @@ export class LinkUpdateReducer {
|
||||
if (!state.seen[path]) {
|
||||
state.seen[path] = {};
|
||||
}
|
||||
here.page.map(submission => {
|
||||
(here.page || []).map(submission => {
|
||||
state.seen[path][submission.url] = submission.seen;
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user