Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/use etag from upstream #390

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Feat/use etag from upstream #390

wants to merge 6 commits into from

Conversation

chriswk
Copy link
Member

@chriswk chriswk commented Jan 15, 2024

This changes our client features endpoint to rely on etag we get from upstream, avoiding doing the service call and just returning 304 if we match.


fn new_transform(&self, service: S) -> Self::Future {
ok(EdgeETagMiddleware {
service: service,

Check warning

Code scanning / clippy

redundant field names in struct initialization Warning

redundant field names in struct initialization
server/src/filters.rs Fixed Show fixed Hide fixed
server/src/middleware/etag.rs Fixed Show fixed Hide fixed
server/src/middleware/etag.rs Fixed Show fixed Hide fixed
@chriswk chriswk force-pushed the feat/useEtagFromUpstream branch 2 times, most recently from 2137ff8 to 7fefc52 Compare January 15, 2024 13:01
use super::*;

#[test]
fn building_an_initial_state_from_backup_also_adds_etags_for_features() {
Copy link
Member

Choose a reason for hiding this comment

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

Nice test case!

client_token: &Option<EdgeToken>,
if_none_match: &Option<IfNoneMatch>,
) -> bool {
match (if_none_match, client_token) {
Copy link
Member

@sighphyre sighphyre Jan 17, 2024

Choose a reason for hiding this comment

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

The match one looks odd to me here. You can do a tuple destructuring if let Some here:

fn we_know_this_etag_from_upstream(
    etag_cache: Arc<DashMap<EdgeToken, EntityTag>>,
    client_token: &Option<EdgeToken>,
    if_none_match: &Option<IfNoneMatch>,
) -> bool {
    if let (Some(if_none), Some(token)) = (if_none_match, client_token) {
        etag_cache.get(token).map_or(false, |etag| {
            if_none == &IfNoneMatch::Any || if_none.to_string() == etag.to_string()
        })
    } else {
        false
    }
}

Entirely optional

Copy link
Member

@sighphyre sighphyre left a comment

Choose a reason for hiding this comment

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

Nice! Small comment, up to you if you want to do anything with it

@chriswk chriswk mentioned this pull request Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Approved PRs
Development

Successfully merging this pull request may close these issues.

2 participants