Skip to content

Commit

Permalink
Jetpack Scan: remove polling request limit, adjust scan state render …
Browse files Browse the repository at this point in the history
…conditions (#96250)
  • Loading branch information
nateweller authored Nov 11, 2024
1 parent 789619f commit 6de6fc4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 40 deletions.
22 changes: 5 additions & 17 deletions client/my-sites/scan/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { getCount } from 'calypso/state/persistent-counter/selectors';
import getSettingsUrl from 'calypso/state/selectors/get-settings-url';
import getSiteScanIsInitial from 'calypso/state/selectors/get-site-scan-is-initial';
import getSiteScanProgress from 'calypso/state/selectors/get-site-scan-progress';
import getSiteScanRequestRetryCount from 'calypso/state/selectors/get-site-scan-request-retry-count';
import getSiteScanRequestStatus from 'calypso/state/selectors/get-site-scan-request-status';
import getSiteScanState from 'calypso/state/selectors/get-site-scan-state';
import isRequestingJetpackScan from 'calypso/state/selectors/is-requesting-jetpack-scan';
Expand All @@ -53,7 +52,6 @@ interface Props {
isRequestingScan?: boolean;
scanPageVisitCount?: number;
scanRequestStatus?: 'pending' | 'success' | 'failed';
scanRequestRetryCount?: number;
timezone: string | null;
gmtOffset: number | null;
moment: {
Expand Down Expand Up @@ -244,19 +242,14 @@ class ScanPage extends Component< Props > {
}

renderScanState() {
const { site, scanState, isRequestingScan, scanRequestStatus, scanRequestRetryCount } =
this.props;
const { site, scanState, isRequestingScan, scanRequestStatus } = this.props;

// We don't know yet which site we're looking at,
// so show a placeholder until data comes in
// Show the loading placeholder until we have a site to work with.
if ( ! site ) {
return <ScanPlaceholder />;
}

// If we're scanning or preparing to scan, show those statuses;
// importantly, *don't* show the loading placeholder,
// because it disrupts the fluidity of the progress bar

// Show scanning states first - provisioning or in-progress scans take priority.
if ( scanState?.state === 'provisioning' ) {
return (
<>
Expand All @@ -265,15 +258,12 @@ class ScanPage extends Component< Props > {
</>
);
}

if ( scanState?.state === 'scanning' ) {
return this.renderScanning();
}

// *Now* we can show the loading placeholder,
// if in fact we're requesting a Scan status update
// but silently retry if pooling to avoid UI flicker
if ( isRequestingScan && scanRequestRetryCount === 0 ) {
// Show the loading placeholder if we're requesting an update, and have no data to show yet.
if ( ! scanState && isRequestingScan ) {
return <ScanPlaceholder />;
}

Expand Down Expand Up @@ -386,7 +376,6 @@ export default connect(
const isInitialScan = getSiteScanIsInitial( state, siteId );
const scanPageVisitCount = getCount( state, SCAN_VISIT_COUNTER_NAME, false );
const scanRequestStatus = getSiteScanRequestStatus( state, siteId );
const scanRequestRetryCount = getSiteScanRequestRetryCount( state, siteId );

return {
site,
Expand All @@ -399,7 +388,6 @@ export default connect(
isRequestingScan,
scanPageVisitCount,
scanRequestStatus,
scanRequestRetryCount,
};
},
{
Expand Down
10 changes: 0 additions & 10 deletions client/state/data-layer/wpcom/sites/scan/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ const fetchStatus = ( action ) => {

const POOL_EVERY_MILLISECONDS = 5000;

const MAX_RETRY_COUNT = 2;

const onFetchStatusSuccess = ( action, scan ) => ( dispatch ) => {
[
{
Expand Down Expand Up @@ -117,14 +115,6 @@ const onFetchStatusSuccess = ( action, scan ) => ( dispatch ) => {
( threat ) => threat.fixerStatus === 'in_progress'
);
if ( action.pooling && scan.state === 'idle' && threatsFixedInProgress.length > 0 ) {
// Stop pooling after MAX_RETRY_COUNT to prevent infinite rerendering
if ( action.retryCount >= MAX_RETRY_COUNT ) {
dispatch( {
type: JETPACK_SCAN_REQUEST_FAILURE,
siteId: action.siteId,
} );
return;
}
return setTimeout( () => {
dispatch( {
type: JETPACK_SCAN_REQUEST,
Expand Down
13 changes: 0 additions & 13 deletions client/state/selectors/get-site-scan-request-retry-count.ts

This file was deleted.

0 comments on commit 6de6fc4

Please sign in to comment.