Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions lighthouse-core/lib/network-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,37 @@ class NetworkRecorder extends EventEmitter {
}

isIdle() {
return !!this._getActiveIdlePeriod(0);
return this._isActiveIdlePeriod(0);
}

is2Idle() {
return !!this._getActiveIdlePeriod(2);
return this._isActiveIdlePeriod(2);
}

/**
* Returns whether the number of currently inflight requests is less than or
* equal to the number of allowed concurrent requests.
* @param {number} allowedRequests
* @return {boolean}
*/
_getActiveIdlePeriod(allowedRequests) {
const quietPeriods = NetworkRecorder.findNetworkQuietPeriods(this._records, allowedRequests);
return quietPeriods.find(period => !Number.isFinite(period.end));
_isActiveIdlePeriod(allowedRequests) {
let inflightRequests = 0;

for (let i = 0; i < this._records.length; i++) {
const record = this._records[i];
if (!NetworkRecorder.isNetworkRecordFinished(record)) {
if (IGNORED_NETWORK_SCHEMES.includes(record.parsedURL.scheme)) continue;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nesting/mixing and matching seems a bit harder to parse IMO than consistency on one

can I interest in you in

// Request isn't over network, so it doesn't count.
if (IGNORED_NETWORK_SCHEMES.includes(record.parsedURL.scheme)) continue;
// Request finished, so it's not inflight.
if (NetworkRecorder.isNetworkRecordFinished(record))) continue;
// Request is inflight.
inflightRequests++;

or

if (!NetworkRecorder.isNetworkRecordFinished(record) && 
    !IGNORED_NETWORK_SCHEMES.includes(record.parsedURL.scheme)) {
  inflightRequests++;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nesting/mixing and matching seems a bit harder to parse IMO than consistency on one

sure, looks better


inflightRequests++;
}
}

return inflightRequests <= allowedRequests;
}

_emitNetworkStatus() {
const zeroQuiet = this._getActiveIdlePeriod(0);
const twoQuiet = this._getActiveIdlePeriod(2);
const zeroQuiet = this.isIdle();
const twoQuiet = this.is2Idle();

if (twoQuiet && zeroQuiet) {
log.verbose('NetworkRecorder', 'network fully-quiet');
Expand Down