Skip to content

Commit

Permalink
Remove ugly messages and implement freshness
Browse files Browse the repository at this point in the history
  • Loading branch information
dmsnell committed Apr 12, 2018
1 parent b272342 commit 0d9243c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
5 changes: 0 additions & 5 deletions client/my-sites/stats/activity-log/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import {
getActivityLog,
getActivityLogs,
getBackupProgress,
getHttpData,
getRequest,
getRequestedBackup,
getRequestedRewind,
Expand All @@ -62,7 +61,6 @@ import {
getSiteTimezoneValue,
getOldestItemTs,
} from 'state/selectors';
import * as ids from 'state/resource-ids';

const flushEmptyDays = days => [
days.length === 1 ? 'empty-day' : 'empty-range',
Expand Down Expand Up @@ -464,7 +462,6 @@ class ActivityLog extends Component {
rewindState,
siteId,
slug,
tags,
translate,
} = this.props;

Expand Down Expand Up @@ -494,7 +491,6 @@ class ActivityLog extends Component {

return (
<div>
{ tags && <div>Tags: { tags.length }</div> }
<QueryActivityLog siteId={ siteId } { ...logRequestQuery } />
{ siteId &&
'active' === rewindState.state && <QueryRewindBackupStatus siteId={ siteId } /> }
Expand Down Expand Up @@ -661,7 +657,6 @@ export default connect(
siteId,
siteTitle: getSiteTitle( state, siteId ),
slug: getSiteSlug( state, siteId ),
tags: getHttpData( ids.readerTags() ).data,
timezone,
oldestItemTs: getOldestItemTs( state, siteId ),
};
Expand Down
22 changes: 17 additions & 5 deletions client/state/data-layer/http-data/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ export const update = ( id, state, data ) => {
}
};

export const requestHttpData = ( id, action, { fromApi } ) =>
'function' === typeof fromApi
? { type: HTTP_DATA_REQUEST, id, fetch: action, fromApi }
: { type: HTTP_DATA_REQUEST, id, fetch: action };

const empty = Object.freeze( {
state: 'uninitialized',
data: undefined,
Expand All @@ -62,6 +57,23 @@ const empty = Object.freeze( {

export const getHttpData = id => httpData.get( id ) || empty;

export const requestHttpData = ( id, action, { fromApi, freshness } ) => {
const request = { type: HTTP_DATA_REQUEST, id, fetch: action, fromApi };

if ( 'number' !== typeof freshness ) {
return request;
}

const { lastUpdated, state } = getHttpData( id );
const staleness = Date.now() - lastUpdated;
if ( 'pending' === state || staleness < freshness ) {
// an empty thunk performs no dispatch
return () => undefined;
}

return request;
};

window.httpData = httpData;
window.getHttpData = getHttpData;
window.requestHttpData = requestHttpData;

0 comments on commit 0d9243c

Please sign in to comment.