-
Notifications
You must be signed in to change notification settings - Fork 300
Remove blocking IO #1803
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
Remove blocking IO #1803
Conversation
|
||
impl Default for RustReleasePost { | ||
fn default() -> Self { | ||
Self(Default::default(), Instant::now()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is consistent with the previous behavior: If no version (or release post) can be fetched, an empty string is used instead. Not sure how much sense that makes though.
teams: RustTeams::get(teams_cache) | ||
.await | ||
.0 | ||
.ok_or_else(|| Box::<dyn Error + Send + Sync>::from("failed to load teams"))?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The teams data does currently cause an error if it cannot be fetched (unlike rust version and release post) so I used an option in the cache type to indicate there might not be any teams data.
let rust_version = RustVersion::fetch().await.unwrap_or_default(); | ||
let rust_release_post = RustReleasePost::fetch().await.unwrap_or_default(); | ||
let teams = RustTeams::fetch().await.unwrap_or_default(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a change in behavior, the caches will now already be prefilled with data at startup. Previously, I think the first request using a cache would actually block until some data could be retrieved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's a good call, yeah.
src/main.rs
Outdated
async fn index() -> Template { | ||
render_index(ENGLISH.into()).await | ||
async fn index( | ||
version_cache: &State<Arc<RwLock<RustVersion>>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we use some kind of typedef for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trait Cached
+ type Cache<T> = ...
would probably be fine. Open to other opinions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's cleaner 👍
let rust_version = RustVersion::fetch().await.unwrap_or_default(); | ||
let rust_release_post = RustReleasePost::fetch().await.unwrap_or_default(); | ||
let teams = RustTeams::fetch().await.unwrap_or_default(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's a good call, yeah.
I had another go at removing the remaining blocking IO in
cache.rs
. The main problem I had previously encountered was that passing function pointers toasync
functions is very messy. I usedasync_trait
to not have to do that in the first place. In the process, I switched over to Rocket's managed state. This reduces complexity incache.rs
and theoretically even improves performance a bit, since there are now three separate caches, with separateRwLock
s, which should reduce lock contention.