Skip to content
This repository was archived by the owner on Jan 29, 2026. It is now read-only.

feat(cachePolicy): [INFRA-1290] Add CDN caching for fx proxy recommendations#48

Merged
Herraj merged 2 commits intomainfrom
infra-1290-cdn-caching-for-fx-proxy-recommendations
May 12, 2023
Merged

feat(cachePolicy): [INFRA-1290] Add CDN caching for fx proxy recommendations#48
Herraj merged 2 commits intomainfrom
infra-1290-cdn-caching-for-fx-proxy-recommendations

Conversation

@Herraj
Copy link
Copy Markdown
Contributor

@Herraj Herraj commented May 11, 2023

Goal

Add CDN caching for fx proxy recommendations

I'd love feedback/perspectives on:

See review comments

References

JIRA ticket:

@Herraj Herraj requested a review from a team as a code owner May 11, 2023 21:27
@Herraj Herraj self-assigned this May 11, 2023
@Herraj Herraj requested a review from a team as a code owner May 11, 2023 21:27
@Herraj Herraj requested review from cmharlow and kschelonka May 11, 2023 21:27
.expect('Cache-control', 'public, max-age=1800'); // assert the Cache-control header is overwritten by the /v1/recommendations route

expect(res.status).toEqual(200);
expect(res.headers['cache-control']).toEqual('public, max-age=1800');
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can either use the line 76 way, which is using the supertest library way of asserting on headers e.t.c or I can do it line 79 way which mirrors the existing pattern?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Either one is fine. I don't think it's materially different.

}
return next();
};
};
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

very very tiny refactor to get rid of the eslint / prettier errors. Works as expected but I wasn't sure the original intent behind not having a return and having nested arrow functions 🤔

Can revert

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is equivalent.

It's just another syntax that can avoid nesting if your lint rules allow it.

Typically when I use higher order functions I would format it like this:

const CacheControlHandler =
  (cachePolicy: string, config: typeof ConfigFile) =>
  (req: Request, res: Response, next: NextFunction): void => {
    ...

The second function is interpreted as single expression and implicitly returns. It's nice and concise, but the eslint / prettier rules don't really like this at all though. Docs

'/v1/recommendations',
// request must include a consumer
ConsumerKeyHandler,
CacheControlHandler('public, max-age=1800', config),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't have much knowledge around Web repo but I'm assuming this is where web repo sets the cache time limit for recommendations:

https://github.com/Pocket/Web/blob/f50a32402077629b61c55930941814c442a6ff19/public_html/v3/firefox/global-recs.php#L33

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That looks correct to me.

Copy link
Copy Markdown
Contributor

@hyperparabolic hyperparabolic left a comment

Choose a reason for hiding this comment

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

I'd drop one of the cache-control checks in the test. I think this is good to go otherwise, pre-approved.

@Herraj Herraj merged commit 86f454c into main May 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants