Skip to content

Commit

Permalink
fix(πŸ›): Skip all response caches when response caching is disabled (#537
Browse files Browse the repository at this point in the history
)

* fix(πŸ›): Skip all response caches when response caching is disabled

* 🏷️ Add useless type to satisfy the compiler
  • Loading branch information
Wil Wilsman committed Jul 22, 2020
1 parent bf94471 commit 6ddb9a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/services/asset-discovery-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ export class AssetDiscoveryService extends PercyClientService {
super()
this.browser = null
this.pagePool = null
this.configuration = configuration || DEFAULT_CONFIGURATION.agent['asset-discovery']
this.responseService = new ResponseService(buildId, this.configuration['allowed-hostnames'])

this.configuration = configuration ||
DEFAULT_CONFIGURATION.agent['asset-discovery']

this.responseService = new ResponseService(
buildId,
this.configuration['allowed-hostnames'],
this.configuration['cache-responses']
)
}

async setup() {
Expand Down
8 changes: 5 additions & 3 deletions src/services/response-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ export default class ResponseService extends PercyClientService {
resourceService: ResourceService
responsesProcessed: Map<string, string> = new Map()
allowedHostnames: string[]
cacheResponses: boolean

constructor(buildId: number, allowedHostnames: string[]) {
constructor(buildId: number, allowedHostnames: string[], cacheResponses: boolean) {
super()
this.resourceService = new ResourceService(buildId)
this.allowedHostnames = allowedHostnames
this.cacheResponses = cacheResponses
}

shouldCaptureResource(rootUrl: string, resourceUrl: string): boolean {
Expand All @@ -51,9 +53,9 @@ export default class ResponseService extends PercyClientService {
logger.debug(addLogDate(`processing response: ${response.url()} for width: ${width}`))
const url = this.parseRequestPath(response.url())

// skip responses already processed
// skip responses already processed unless the response cache is disabled
const processResponse = this.responsesProcessed.get(url)
if (processResponse) { return processResponse }
if (this.cacheResponses && processResponse) { return processResponse }

const request = response.request()
const parsedRootResourceUrl = new URL(rootResourceUrl)
Expand Down

0 comments on commit 6ddb9a0

Please sign in to comment.