lighthouse-plugin-publisher-ads/utils/graph.js
/**
 * Summarizes the given array of requests by merging overlapping requests with
 * the same url. The resulting array will be ordered by start time.
 * @param {SimpleRequest[]} requests
 * @return {SimpleRequest[]}
 */
Summarizes the given array of requests by merging overlapping requests with
the same url. The resulting array will be ordered by start time.
Summarizes the given array of requests by merging overlapping requests with the same url . The resulting array will be ordered by start time .
function computeSummaries(requests) {
  requests.sort((a, b) => {
    if (a.nameOrTld != b.nameOrTld) {
      return a.nameOrTld < b.nameOrTld ? -1 : 1;
    }
    if (a.type != b.type) {
      return a.type < b.type ? -1 : 1;
    }
    if (a.startTime != b.startTime) {
      return a.startTime < b.startTime ? -1 : 1;
    }
    return a.endTime - b.endTime;
  });
  const result = [];
  for (let i = 0; i < requests.length; i++) {
    const current = requests[i];
    let next;
    while (i < requests.length) {
      next = requests[i + 1];
      if (!next || !areSimilarRequests(next, current)) {
        break;
      }
      current.endTime = Math.max(current.endTime, next.endTime);
      current.duration = current.endTime - current.startTime;
      i++;
    }
    result.push(current);
  }
  result.sort((a, b) => a.startTime - b.startTime);
  return result;
}
function computeSummaries ( requests ) { requests . sort ( ( a , b ) => { if ( a . nameOrTld != b . nameOrTld ) { return a . nameOrTld < b . nameOrTld ? - 1 : 1 ; } if ( a . type != b . type ) { return a . type < b . type ? - 1 : 1 ; } if ( a . startTime != b . startTime ) { return a . startTime < b . startTime ? - 1 : 1 ; } return a . endTime - b . endTime ; } ) ; const result = [ ] ; for ( let i = 0 ; i < requests . length ; i ++ ) { const current = requests [ i ] ; let next ; while ( i < requests . length ) { next = requests [ i + 1 ] ; if ( ! next || ! areSimilarRequests ( next , current ) ) { break ; } current . endTime = Math . max ( current . endTime , next . endTime ) ; current . duration = current . endTime - current . startTime ; i ++ ; } result . push ( current ) ; } result . sort ( ( a , b ) => a . startTime - b . startTime ) ; return result ; }
Summarizes the given array of requests by merging overlapping requests with
 the same url.
Summarizes the given array of requests by merging overlapping requests with the same url .
// Sort requests by URL first since we will merge overlapping records with // the same URL below, using a similar algorithm to std::unique. // Within a url, we sort by time to make overlap checks easier.