Skip to content

Commit

Permalink
perf(nginx): Micro optimization in map
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Jan 12, 2024
1 parent f5f54fb commit 955f836
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@

# extract $user_id_location from first 3 characters of `user-id` header.
map $http_user_id $user_id_location {
"~^(?<prefix>.{3})" $storeRegionPerUser/$prefix/$http_user_id;
default '';
# Micro optimization: if user-id is empty, don't bother with regex.
'' '';
"~^(?<prefix>.{3})" $storeRegionPerUser/$prefix/$http_user_id;
}

# extract $user_token_location from first 3 characters of `user-token` header.
map $http_user_token $user_token_location {
"~^(?<prefix>.{3})" $storeRegionPerToken/$prefix/$http_user_token;
default '';
'' '';
"~^(?<prefix>.{3})" $storeRegionPerToken/$prefix/$http_user_token;
}

# extract $device_id_location from first 3 characters of `device-id` header.
map $http_device_id $device_id_location {
"~^(?<prefix>.{3})" $storeRegionPerDevice/$prefix/$http_device_id;
default '';
'' '';
"~^(?<prefix>.{3})" $storeRegionPerDevice/$prefix/$http_device_id;
}

0 comments on commit 955f836

Please sign in to comment.