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

Improve perf and docs for Plug.RequestId #1178

Merged
merged 1 commit into from
Oct 13, 2023
Merged

Conversation

whatyouhide
Copy link
Member

This is a plug that gets called A LOT in most applications, so if we can do something more efficiently I believe we should 🙃

[val | _] -> if valid_request_id?(val), do: {conn, val}, else: {conn, generate_request_id()}
end
end
request_id = get_request_id(conn, header)
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't need to pass in the conn to get_request_id/2 and return it, because we don't update it. One less tuple allocation and one less function call.

Comment on lines +25 to +28
> #### Programmatic access to the request ID {: .tip}
>
> To access the request ID programmatically, use the `:assign_as` option (see below)
> to assign the request ID to a key in `conn.assigns`, and then fetch it from there.
Copy link
Member Author

Choose a reason for hiding this comment

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

Do I love me some admonition blocks

@josevalim josevalim merged commit 7ac742f into main Oct 13, 2023
2 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@josevalim josevalim deleted the al/plug-req-id-perf branch October 13, 2023 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants